New information
This is what happens with rails console
:
Loading development environment (Rails 3.1.1)
ruby-1.9.2-p290 :001 > RUBY_VERSION
=> "1.8.7"
There's something really weird going on here - the prompt says 1.9.2
but RUBY_VERSION
shows 1.8.7
.
I'm using RVM, but I'm having problems with Rails on Ubuntu.
$ which ruby
/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
$rvm list
rvm rubies
=> ruby-1.9.2-p290 [ i686 ]
But if I do gem env
I get
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
- INSTALLATION DIRECTORY: /home/nick/.rvm/gems/ruby-1.9.2-p290
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /home/nick/.rvm/gems/ruby-1.9.2-p290/bin
and when I run Rails, if I do puts RUBY_VERSION
it outputs 1.8.7
.
In fact, in irb
, RUBY_VERSION
gives 1.9.2
but in rails console
it gives 1.8.7
.
The main problem is that it's failing when it gets to my JSON-style hash-literals.
I've tried various approaches of uninstalling rvm, rails, bundler, etc. but nothing seems to work. Any ideas?
EDIT:
Here is the output of rvm info
:
ruby-1.9.2-p290:
system:
uname: "Linux ubie 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:50:42 UTC 2011 i686 i686 i386 GNU/Linux"
bash: "/bin/bash => GNU bash, version 4.2.10(1)-release (i686-pc-linux-gnu)"
zsh: " => not installed"
rvm:
version: "rvm 1.8.6 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]"
ruby:
interpreter: "ruby"
version: "1.9.2p290"
date: "2011-07-09"
platform: "i686-linux"
patchlevel: "2011-07-09 revision 32553"
full_version: "ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]"
homes:
gem: "/home/nick/.rvm/gems/ruby-1.9.2-p290"
ruby: "/home/nick/.rvm/rubies/ruby-1.9.2-p290"
binaries:
ruby: "/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin/ruby"
irb: "/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin/irb"
gem: "/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin/gem"
rake: "/home/nick/.rvm/gems/ruby-1.9.2-p290/bin/rake"
environment:
PATH: "/home/nick/.rvm/gems/ruby-1.9.2-p290/bin:/home/nick/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin:/home/nick/.rvm/bin:/home/nick/local/node/bin:/home/nick/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
GEM_HOME: "/home/nick/.rvm/gems/ruby-1.9.2-p290"
GEM_PATH: "/home/nick/.rvm/gems/ruby-1.9.2-p290:/home/nick/.rvm/gems/ruby-1.9.2-p290@global"
MY_RUBY_HOME: "/home/nick/.rvm/rubies/ruby-1.9.2-p290"
IRBRC: "/home/nick/.rvm/rubies/ruby-1.9.2-p290/.irbrc"
RUBYOPT: ""
gemset: ""
but still gem env
tells me that in the RubyGems Environment the Ruby version is 1.8.7
. I just don't get it.
Try to use:
I would go for bad gem/rails install:
You should set default ruby like:
This will override system installed ruby with rvm one.
Updated:
notme, thank you for remark
Leading double hyphen before default is significant to set default ruby.
Below listed detailed & self-explained example, enjoy:
Most likely Culprit:
Check your PATH environment variable by typing
printenv PATH
in the shell -- /usr/bin might come before wherever RVM installs it's Rubies -- but you don't want that when using RVM!!If /usr/bin comes before the RVM-location, when checking for programs, it will take /usr/bin/ruby -- the Ruby which came with your LINUX (most likely 1.8.7) -- not the RVM default ruby (which is 1.9.2)
You can double check this like this by asking your system
which ruby
:Check your PATH environment variable -- make sure that the directory where your RVM ruby version is installed comes FIRST, before /usr/bin
e.g. in my PATH, the ~/.rvm/... comes first, then /usr/local/bin, then /usr/bin (with a couple of other dirs of course)
as mentioned before,
rvm --default use 1.9.2
, so you get the default Ruby version in any new shell.Looks like you have installed RVM system-wide under /usr/local.
IMHO system-wide installation can be a mess when upgrading gems, and it can cause a couple of problems going forward.
I would not recommend doing that! I had a longer email discussion with Wayne Seguin, and even he uses local user RVM for his environments.
Check the RVM docu - it says there: Please note that Single-User supercedes Multi-User [...RVM installation].
That means that if you have installed RVM system-wide, and you also (accidentially?) installed it for a user account, then for that user, the locally installed RVM takes precedence. This is an extra pit-fall which is easy to avoid by not installing system-wide in the first place :)
Personally, I would uninstall the system-wide RVM and install it only for the relevant user(s), who can then more easily install their gems themselves without interfering with other users.
Finally: when installing local to the user account, make sure that you install your gems specifically for the correct Ruby version, and that you do not use sudo to install the gems!
hopes this helps! good luck!
EDIT
If you're getting different output from RUBY_VERSION than your irb or rails console prompt, then there must be something amiss with the way Ruby was compiled / installed. This looks more and more like you need to re-install RVM and your Ruby version 1.9.2, but first check your PATH, to make sure that's not the culprit.
A Sanity Check, to check if there is interference from your LINUX installation:
create a new user account, do a new RVM install for that user and install Ruby 1.9.2 -- then try if it works in that account, or if it shows the same problems.
Are you using Passenger or Pow to run your Rails apps? If so you'll need to set the server to use rvm 1.9.2
See section 2.3 here, for example: http://pow.cx/manual.html#section_2
Or for passenger: http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/
Do you have a
.rvmrc
file in your user directory?It should look something like that?
And also check you've set up a
.bashrc
file like this: