Ruby Version Manager, aka RVM, is a command line tool designed to manage multiple installations of Ruby on the same device. In addition to allowing you to install and use multiple Ruby versions, it has other interesting features that you can use to maintain organization between projects with different gems. In this article I will explain my basic workflow and also some tips on using RVM. I do suppose that RVM is already installed.
RVM Basic Commands
Basic syntax: rvm, a category, and a command for that category.
To list known rubies, or the ruby versions that are available to install:
To install a Ruby version:
To list all rubies and gemsets installed in your computer
Selecting Ruby to work
Defining the default version to use (you can refer to it as default)
Using the default ruby version
RVM by default allows creating multiple environments for one ruby - called gemsets. Gemsets is a feature that allows you manage gem versions, so it is possible to define a package (or set)of gems with a specific version. When assigning a gemset to a project you ensure that you have an isolated environment acessing the correct version of each gem.
During installation of Ruby, RVM creates two gemsets:
- default - automatically selected when no @gemset specified: rvm use 1.9.3
- global - super gemset, inherited by all other gemsets for the given ruby
To create a gemset:
Using a gemset:
or Gemsets can be specified together with ruby name using gemsets separator(@):
To create a gemset and already use it:
All gems that you install when using gemset will be confined to it. In the list of gems will appear only the gems of the gemset and those of the global gemset.
If you want to install a new gem to the global gemset, use:
To see which gemset is being used:
Listing all available gemsets for the version:
Deleting a gemset and the gems contained in it (-force is not to ask for confirmation):
Where are the gems installed? Type:
That will result in something like:
In my case (using OS X El Capitan) I have all gemsets installed at /users/foss/gems
Separate Gemset to each project
Whenever you change to a directory (cd directory), RVM checks if there is a .rvmrc inside it. This file is a shell script that can contain any code needed to initialize the project environment. For example, if you want to load a gemset with a specific ruby version every time you enter the project directory, you just need to create a .rvmrc with the content:
With that in mind, I standardized the setup of my projects to:
The last command will create a gemset for the project, and also the .rvmrc to load the correct gemset. As I am also using bundler, I create a Gemfile, listing the dependencies of the project, (even in older projects, with Rails 1.2.6). Then just install them with:
So, I have an isolated gems environment for each project, and the best, every time I switch to a project directory, RVM will already load the correct gemset based on .rvmrc!
Other rvm commands
To have a list of the available commands:
To get help on a specific command:
If you want to uninstall a version of Ruby:
To delete a gemset:
Check the RVM website for a detailed (and good) documentation at https://rvm.io/