Named Gem Sets
RVM gives you compartmentalized independent ruby setups. This means that ruby, gems and irb are all separate and self-contained - from the system, and from each other.
You may even have separate named gemsets.
Let's say, for example, that you are testing two versions of a gem, with ruby 1.9.2-head. You can install one to the default 1.9.2-head, then create a named gemset for the other version, and switch between them easily.
Example: testing gems
$ rvm 1.9.2-head@testing
will use a '1.9.2-head@testing' GEM_HOME (be sure to create it first), whereas:
$ rvm 1.9.2-head
will use the default 1.9.2-head GEM_HOME :)
Example: Rails versions & upgrading apps
To illustrate the point, let's talk about a common use case. Assume you are testing out a rails application against a new Rails release. RVM makes such testing very easy, by letting you quickly switch between multiple Rails versions. First, let's set up the environments:
$ rvm 1.9.2-head $ gem install rails -v 2.3.3 $ rvm gemset create rails222 rails126 Gemset 'rails222' created. Gemset 'rails126' created. $ rvm 1.9.2-head@rails222 $ gem install rails -v 2.2.2 $ rvm 1.9.2-head@rails126 $ gem install rails -v 1.2.6 $ rvm 1.8.7 $ gem install rails -v 1.2.3
Note that, for each of the ruby installs above, you can have completely separate versions!
Now that your environments are set up, you can simply switch between Rails versions and Ruby versions as follows.
$ rvm 1.9.2-head@rails126 ; rails --version Rails 1.2.6 $ rvm 1.8.7 ; rails --version Rails 1.2.3 $ rvm 1.9.2-head@rails220 ; rails --version Rails 2.2.0 $ rvm 1.9.2-head ; rails --version Rails 2.3.3
If you are deploying to a server, or you do not want to wait around for rdoc and ri to install for each gem, you can disable them for gem installs and updates. Just add these two lines to your ~/.gemrc or /etc/gemrc:
install: --no-rdoc --no-ri update: --no-rdoc --no-ri
Note: You likely do not want to run this for *every* gem command, as these args would break some 'gem X' commands. Which is why I did not use 'gem: --no-rdoc --no-ri' in the example above.
Warning!!!
* RVM gives you a separate gem directory for
NOTE: A little bit about where the default and global gemsets differ. If you don't use a gemset at all, you get the gems in the 'default' set. If you use a specific gemset (say @testing), it will inherit gems from that ruby's @global. The 'global' gemset is to allow you to share gems to all your gemsets. The word 'default' quite literally says it all, eg. the gemset used without selecting one for a specific installed ruby.
Although I recommend against it, you can use 'rvm gemdup default' and 'rvm gemdup system' to clone user-default gems and system gems respectively. Unless of course I decide to remove this feature, as I am not convinced it is worthwhile :)