RVM, or Ruby Version Manager, has revolutionized how we install and manage Ruby. Given the rapid pace of development in our community, it is common that a developer will need to have access to both Ruby 1.8.7 for older projects and Ruby 1.9.2 for newer ones. They might also choose to use alternative Ruby interpreters like JRuby or Rubinius. Installing and maintaining all these by hand is extremely difficult.
Enter RVM. The RVM system actually contains no Ruby code – it’s a collection of terminal scripts that can make managing multiple versions of Ruby transparent and easy. Even if you are only using one version of Ruby today, you’ll still gain great benefits from RVM.
Let me put it this way: if you’re on a Unix-based system (including, of course, OSX) and not using RVM, you are doing it wrong!
Generally RVM can be setup in three steps. (Detailed installation/setup instructions can be found on the RVM site.)
Install from source (in the terminal)
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Add these lines to your
[[ -s $HOME/.rvm/scripts/rvm ]] && . $HOME/.rvm/scripts/rvm [[ -r $HOME/.rvm/scripts/completion ]] && . $HOME/.rvm/scripts/completion
Re-process your profile (in the terminal):
Validate RVM is installed by running
rvm info and you should see lots of information about your environment.
Setup Global Gems
You can setup RVM to add certain gems to all versions of Ruby and all gemsets. Use restraint here, but generally all Ruby apps should use Bundler (http://gembundler.com/) for dependency management. Create a file
~/.rvm/gemsets/global.gems and just add this line:
Bundler will now be setup for new Rubies and added to new gemsets.
Once you have access to the RVM system you’re ready to install Ruby. To see what versions of Ruby are available you can run
rvm list known in the terminal.
For these tutorials we’ll be using Ruby 1.9.2, install it with the following commands. Note that
$ is the terminal prompt:
Then tell RVM to make it our default Ruby:
Test it by displaying the Ruby version and you should see something like this:
Once your RVM ruby version is selected, just run
gem like normal.
RVM installs Ruby into the user space, so you do not need to use `sudo`, ever. If you’re following an older book or tutorial and it has `sudo` in an instruction, just omit the `sudo`.