Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling ruby version used in Rails

I have an app using Rails 3.0.6 which I run on two machines. I started with ruby 1.8.7 and recently installed ruby 1.9. I swapped my link in '/usr/bin/ruby' to point to the 1.9 install. When I run 'ruby --version' I get the 1.9. However, in my rails app, when I check 'RUBY_PLATFORM' it shows rails is running with 1.8.7.

How do I tell Rails which ruby environment to use? Strangely, this is not the easiest thing to search for. Probably because I don't know enough about it to form a specific question.

like image 235
NJ. Avatar asked May 03 '11 03:05

NJ.


People also ask

What version of ruby does Rails use?

1.2 Ruby VersionsRails 7 requires Ruby 2.7. 0 or newer. Rails 6 requires Ruby 2.5. 0 or newer.

Which Ruby Version Manager is best?

Along with RVM, Rbenv has long been the most popular version manager for Ruby. Rbenv uses shims to intercept common Ruby commands. (Asdf also uses shims.) After installing Rbenv with Homebrew, you must modify your ~/.


1 Answers

https://rvm.io/rvm/install

Install RVM using these instructions, then you can manage and switch between different Ruby versions and gemsets very easily. Using RVM you can have both 1.8.7 and 1.9.x (or any other version) on your system without having to constantly manually change your path and ruby alias.

Older versions of RVM used the .rvmrc file to automatically switch the ruby within a directory. Newer versions use the .ruby-version file.

To switch between rubies, just type rvm use 2.0.0 or whatever version it is you want to use. For ongoing projects it's a good idea to add the .ruby-version file in the root of the directory that contains the version string you want to use, i.e.

2.0.0
like image 63
Josh Kovach Avatar answered Oct 26 '22 13:10

Josh Kovach