Software Development | Ruby on Rails
Managing Versions of Ruby, Rails and Gems

Macs now come with Ruby on Rails installed but I was wary of modifying what Apple gave me yet wanted to try out Rails 3. Luckily there are now tools to make this really easy.

RVM: Managing versions of Ruby

Hivelogic: Compiling Ruby, RubyGems, and Rails on Snow Leopard recommends installing Ruby and Rails separately from the Apple provided system Ruby on Rails. He installs Ruby on Rails in /usr/local. Here are the stated reasons from Hivelogic:

  • You want to run the latest/greatest versions of available software and don’t want to wait (or hope) for Apple to release an update.
  • Your want to update, tweak, and customize your own tools while keeping your system “stock” from Apple’s standpoint.
  • Apple may decide to modify these utilities during a system update, and doing so may break your stuff.
  • You can move or remove the /usr/local filesystem, or even transfer it to another machine in one step.
  • You’re used to, interested in, or curious about in the compile and build process.

All fair enough but you get all this and more, and from my perspective easier, by using RVM. I spotted RVM on RailsCasts 200: Rails 3 beta and RVM and it looked pretty good. With RVM you can install multiple versions of Ruby, with Rails installed as well, and easily switch between them. This is great in maintenance mode when you've got legacy systems to support but want to use the latest version for new systems.

I use Ruby 1.8.7 with Rails 2.x and Ruby 1.9.2 with Rails 3.0.beta. 

Common RVM commands:

ruby -v                     # returns the version of ruby in use 
rvm install 1.9.2        # rvm installs the specified version of ruby, in this case ruby 1.9.2 
rvm 1.9.2                 # rvm switches to use ruby 1.9.2
rvm 1.9.2 --default    # rvm makes ruby 1.9.2 the default so new terminal windows will get this version
rvm system              # rvm switches to the system installed version of ruby 
rvm system --default # rvm makes the system installed version of ruby the default 

The only gem you install is Rails itself. Everything else gets installed with bundler. And even then bundler should manage subsequent updates to Rails.

Bundler: Managing Gem dependencies 

Bundler is the way to manage gem dependencies in Rails 3 applications. There are many tutorials on bundler (e.g. RailsCasts 201: Bundler) so I'll just list the major commands:

bundle install                      # go through the application's gem dependencies and install them
bundle check                      # list the gems that our application depends on but which aren't installed
bundle install --without=test # install the gems that aren't in the test group
bundle lock                         # locks down the specific versions of the gems your application is using
bundle install --relock          # unlock the gemfile, update the gems and then re-lock