Managing Gem Dependencies with Rails >= 2.0.3

January 17, 2009

Here's how I manage gem dependencies for Rails applications running version 2.0.3 or later.

Specify your dependencies in config/environment.rb:

Rails::Initializer.run do |config|
  # ...
  config.gem 'doodle'
  config.gem 'aws-s3', :lib => 'aws/s3'
  config.gem 'smqueue', :version => '0.1.0'
  # ...
end

I don't want deployments to depend on gem sources being available, so I pull the gems into the source tree and check them in:

sudo rake gems:install
rake gems:unpack
svn add vendor/gems/*

At deploy time, remember to build any gems that have native extensions:

rake gems:build

If you have a build system that produces application packages, this should be part of that packaging step. If you're using Capistrano, hook it into an after deploy:update_code callback.

Questions or thoughts? Get in touch.