How to install and use different versions of ruby?

There are two "Ruby version managers" out there, which you can choose from:

  • rbenv and ruby-build
  • RVM

These allow you to keep multiple versions of Ruby on the same system. Once you've installed a version manager, and installed your own Ruby version, you won't mess with your system's Ruby and its Gems, which is the greatest benefit. No more sudo! No more permissions errors and Gem conflicts.

Which one should I choose?

Both do the same thing, but they follow different philosophies. The choice is up to you.

I'd personally recommend rbenv for its simplicity. I've been using it since years and it has always worked well. Previously I would have recommended RVM (and an earlier version of this answer actually mentioned it), but I feel it's harder to get into.

How do I install them?

If you choose rbenv:

  • Follow the all the installation and setup instructions.
  • Install ruby-build
  • Run rbenv install x.x.x where x.x.x is the version (use rbenv install --list to see which ones are available
  • Run rbenv global x.x.x to change your global Ruby version

If you choose RVM:

  • Use the secure installation method
  • Read the installation instructions — you probably want the single-user configuration
  • Use rvm list known to list available Rubies and then run rvm install x.x.x to install a specific version.
  • Use rvm use x.x.x --default to change your default Ruby

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.

Tags:

Ruby

Rails