Rails not using correct version of Ruby

╄→гoц情女王★ 提交于 2019-12-03 11:54:23

You should set default ruby like:

rvm use 1.9.2 --default

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:

$ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]

$rvm list
rvm rubies

   ruby-1.9.2-p290 [ i386 ]

$rvm use 1.9.2 --default
Using /usr/local/rvm/gems/ruby-1.9.2-p290

$rvm list default

Default Ruby (for new shells)

   ruby-1.9.2-p290 [ i386 ]

$rvm use default
Using /usr/local/rvm/gems/ruby-1.9.2-p290

$ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]

$rvm list 

rvm rubies

=> ruby-1.9.2-p290 [ i386 ]

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:

which ruby                           # this should be an RVM path! , not /usr/bin
ruby --version                       # you want this to be 1.9.2
/usr/bin/ruby --version              # the old system default Ruby is most likely 1.8.7

~/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
~/.rvm/rubies/default/bin/ruby --version

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.

Do you have a .rvmrc file in your user directory?

$ cat ~/.rvmrc
=> export rvm_path="/home/nick/.rvm"

It should look something like that?

And also check you've set up a .bashrc file like this:

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc 

Try to use:

rvm --default use 1.9.2

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/

I would go for bad gem/rails install:

gem empty
gem update --system
gem install bundler --no-ri --no-rdoc
gem install rails --no-ri --no-rdoc

Make sure you didn't use sudo with RVM. I ran into an issue like this where I had 2 different locations for Ruby and my gems.

PATH is probably wrong - check printenv PATH

Man, I was having this exact problem and the way I solved it was by reinstalling bundler. It seems that bundler was caching the RUBY_VERSION to 1.8.7.

I'm not using rvm, I had to use this to set the default ruby version:

sudo update-alternatives --config ruby
sudo update-alternatives --config gem

And then, I reinstalled bundler and it worked!

Hopefully you can solve it with this approach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!