Wayne E. Seguin describes RVM as:
a command line tool which allows us to easily install, manage and work with multiple ruby environments from interpreters to sets of gems.
This article focuses on the workflow of installing RVM, and use it to install Ruby 1.9.2 (MRI), create gemsets and install Rails 3.1 Release Candidate, while considering current best practices.
Installing Ruby Version Manager
If your Ubuntu 11.04 is still fresh from the oven, you may want to first install git and curl. Having satisfied the prerequisites, installing the latest RVM release version from git is as easy as running:
If at any point you want to start all over, run rvm implode and we'll be ready for a fresh start. For a complete removal, follow these details.
On the other hand, if RVM is already installed but we are behind on the updates,
rvm get latest will do the trick.
Setting up Ruby
- Feel free to run rvm list known for all the Ruby implementation made available through RVM
- We are focusing on the latest stable release, so we'll choose to:
rvm install 1.9.2
- And we will use it as the default version for our system:
rvm use 1.9.2 --default
Gemsets are compartmentalized independent ruby setups, each containing it's own version of ruby, gems and irb. RubyGems — the package manager for Ruby projects — is already available for us, since RVM includes it automatically (try which gem).
For this tutorial we will install side by side the latest Rails stable release (3.0.7) and the latest release candidate (3.1), so let's prepare the terrain:
- Start by creating our gemset(s):
rvm gemset create rails307 rails31
- The result can be verified by listing the available gemsets:
rvm gemset list
- If a gem's name still leaves room for confusion, simply delete it and create a more meaningful one (e.g., rails31rc):
rvm gemset delete rails31
As a best practice, remember to always use one gemset per project*.
- Now that we have multiple gemsets installed, we must first select the one we want to use, and we can also set it as the default gemset by passing it the --default flag:
rvm use 1.9.2-p180@rails307 [--default]
- Installing rails is as easy as installing any other gem: we only need to specify it's name, but we can always choose a specific version, or to speed up the installation process by skipping the documentation:
gem install rails [-v 3.0.7] [--no-rdoc --no-ri]
- Next we switch to the gemset created to hold the latest Release Candidate (e.g., 1.9.2-p180@rails31rc) and we install it by
passing in the --pre flag.
Scratch that; the --pre flag is not working as of June 1st. You might want to read this before installing Rails 3.1, but long story short, this should do the trick:
gem install rails -v ">=3.1.0rc"
Switching from one project to another, from a client to a personal project, from testing the release candidate to developing using the latest stable version, always having to manually switch from using a gemset to another can impact productivity. The project .rvmrc files can increase the development speed by setting up our project's ruby environment when we switch to the project root directory.
The rule of thumb here is to use a .rvmrc file for each project, for both development and deployment.*
* Make sure to check the RVM best practices!
How are gemsets improving your workflow? What other tips & tricks have you discovered while setting up your environment, or while setting up a new project? I would be more than happy to learn something new from you!