Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm learning rails from different books that use different versions of both ruby and rails. Right now I have ruby 1.87 installed on my Mac OS X Snow Leopard (in /usr/bin), but need to also use ruby 1.9 for a different rails application.

Can anyone tell me how to make this work? I'm new to this, so as many instructions as possible would be greatly appreciated.

share|improve this question
up vote 7 down vote accepted

Use Ruby Version Manager. It was meant for keeping multiple versions of Ruby in the same system, even allowing them to use different Gem sets and configurations. You won't mess with your system's Ruby as well, which is another benefit. All your Rubies will be stored in ~/.rvm/rubies, and therefore separated from the system.

There are a few easy steps to get started.

0. Prerequisites

You need Git installed.

  • OS X doesn't ship with it. Install it using the Git OS X installer if you don't care for the ultra-latest version. Otherwise, install it over Homebrew.
  • Linux versions might have it, otherwise just install the git-core package with apt-get or yum.

1. Install RVM

Open up a Terminal and enter

bash < <(curl -s

This takes a while. Read through everything the installer tells you. After the installation, add RVM to your profile (you should have been told that):

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile

Then, close and reopen the terminal, and type rvm to see if everything works. You should get a greeting message.

2. Install Rubies

Install your Ruby versions with RVM now. First of all, enter rvm list known to see a list of all Rubies you can install through RVM. If you've decided, install them like so:

rvm install 1.8.7-head
rvm install 1.9.2

This may take a while, as they are downloaded and compiled on your system. When you're done, you can switch between them.

3. Switch your Rubies

If you have a default Ruby you want to use, change it with the following command.

rvm --default use 1.9.2

To use – for example – the newly installed 1.8.7-head version, just type:

rvm use 1.8.7-head

To switch back to the system's default Ruby (e.g. OS X), type:

rvm use system

You can also reset RVM to use the system Ruby again. This will somewhat disable RVM:

rvm reset

4. Where to go from that?

Now you should be set. This is all you need to know in the beginning. For further resources, check the following articles:

Of course, when working in Rails, don't forget to also update your Rubies and RubyGems (in the latter case with gem update --system).

share|improve this answer
See also rbenv. – grawity Sep 27 '11 at 17:44
@grawity Why not post another answer? Good to have alternatives, haven't really looked into rbenv yet. – slhck Sep 27 '11 at 17:47
thanks so much, does it also help switch between versions of Rails? different books I'm using employ 3.05 (I think) and 3.1 and it's causing problems... – Michael Sep 27 '11 at 18:14
I tried the install line you wrote (and which is also on rvm site) and got an error message: bash: line 152: git: command not found bash: line 154: git: command not found – Michael Sep 27 '11 at 18:17
Ah, you need git, of course. Sorry, I forgot that. You can install Git with the OS X installer (just select the latest version at the top). – slhck Sep 27 '11 at 18:22

I think rbenv deserves at least its own answer.

There is a constant battle between fans of rbenv and those of RVM but I personally like rbenv a lot more. As the Sam Stephenson (the author) states, rbenv it solely concerned with switching Ruby versions (as opposed to RVM, which does a lot more).

On OS X, it's especially easy to give it a try. Just follow the excellent installation instructions on the Github page (if you have Homebrew installed, it's basically just a brew install rbenv ruby-build).

As for switching Rails versions, I once wrote an article about that which my be of interest for you.

share|improve this answer
Here's a brief description of rbenv's author on the main differences with RVM and reasons to choose rbenv. The simplicity of rbenv was the main reason for me to migrate away from RVM. Managing sets of application-specific gems is IMO better done with Bundler - you don't need a Ruby version manager for that. – Jochem Schulenklopper May 31 '15 at 13:32
Exactly – managing sets of application-specific gems is Bundler's job. I have never been a fan of gemsets tied to version managers. – Michael Trojanek Jun 16 '15 at 20:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .