1

I get this error when I navigate to my Rails application in production:

Rails 4 prefers to run on Ruby 2.0.

You're running
  ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]

Please upgrade to Ruby 1.9.3 or newer to continue.

When I type ruby -v in the terminal, I get:

ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]

When type rvm list I get:

rvm rubies

 * ruby-1.9.3-p547 [ x86_64 ]
=> ruby-2.0.0-p481 [ x86_64 ]
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
AhmedShawky
  • 860
  • 2
  • 7
  • 18

4 Answers4

2

You can tell RVM to temporarily use a particular Ruby using:

rvm use 2.0.0

That selected Ruby won't be remembered between launches of command-line sessions, because that doesn't tell RVM to use that version as a default. Add --default and it will:

rvm use 2.0.0 --default

From the built-in help:

To set a ruby as the user default, use the --default option.

    $ rvm use 1.9.3 --default

Please see documentation for further information:

  https://rvm.io/rvm/basics

When I run rvm list, there's some important information displayed that you seem to have overlooked:

rvm list

rvm rubies

   ruby-1.9.3-p547 [ x86_64 ]
=* ruby-2.1.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

Notice the legend showing which is the current and the default Ruby. Compare that to yours.

Also, notice that you're seeing:

ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]

That'd be the version of Ruby installed in the system. Either the user you're running your Rails session as does not have RVM installed and initialized, or somehow RVM is being told to switch to the system Ruby.

Also, you might have a RVM directive in that directory, so read "rvmrc files" and "Typical RVM Project Workflow" to see if something there might be affecting you.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
1

This is my personal opinion: Avoid using RMV on production. There is a tool called alternatives available on CentOS and probably other linux distributions.

ruby_setup.sh

.

#/bin/sh
if [ "$RUBY_VERSION" == '2.0.0' ]; then
  yum -y install ruby20 rubygems20 ruby-devel
  alternatives --set ruby /usr/bin/ruby2.0
elif [ "$RUBY_VERSION" == '1.9.3' ]; then
  yum -y install ruby19 rubygems19 ruby19-devel
  alternatives --set ruby /usr/bin/ruby1.9
elif [ "$RUBY_VERSION" == '1.8.7' ]; then
  yum -y install ruby18 rubygems18 ruby18-devel
  alternatives --set ruby /usr/bin/ruby1.8
else
  exit 1
fi

gem install bundler --no-ri --no-rdoc

.

RUBY_VERSION=2.0.0 ruby_setup.sh
Anatoly
  • 15,298
  • 5
  • 53
  • 77
1

Phusion Passenger author here. RVM commands like rvm use have absolutely no effect on your problem. That's because the Ruby interpreter that Phusion Passenger uses to run your app with, is not controlled from the shell using the rvm command, but only through the use of the passenger_ruby configuration option.

Why is this the case? Because RVM (and rbenv, and chruby, and pretty much anything else out there) are implemented by setting environment variables in the shell. But as explained in the Phusion Passenger manual, environment variables are not system-wide: they are inherited on a per-process basis. Thus, any environment variables you set in bash, only affect bash and its subprocesses, not Nginx. Because the latter is started by the init system.

The passenger_ruby configuration option is the option to control which Ruby interpreter Phusion Passenger gets to use to run your app with.

Hongli
  • 18,682
  • 15
  • 79
  • 107
  • Apart from Passenger you will probably want to perform bundle install and rails console, so no RVM/Rbenv/passenger_ruby should be in place. Use /bin/alternatives and choose required version once and forever. – Anatoly Dec 07 '14 at 08:31
0

You can use this command:

rvm use ruby-2.0.0p481

If this doesn't work try this command as first:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM 

See this similar question: "How do I change my Ruby version using RVM?", and this documentation.

Community
  • 1
  • 1
Mohamed Yakout
  • 2,868
  • 1
  • 25
  • 45