How to Freeze Gems with Rails >= 2.1

I spent a couple of minutes trying to figure out how to ‘freeze’ gems with a recent Rails app (2.2.2) I’m developing. A bunch of git repositories have this vendor/gems folder a bit like in Merb, so I was pretty sure something had changed in Rails itself. I finally found this screencast. I’m sharing it again as I spent a bit of time already myself.

Turns out it’s pretty well integrated. First edit your environment.rb to specify which gem you want to register as a dependency:


Rails::Initializer.run do |config|
  # ...
  # Specify gems that this application depends on. 
  # They can then be installed with "rake gems:install" on new installations.
  # You have to specify the :lib option for libraries, where the Gem name (sqlite3-ruby) differs from the file itself (sqlite3)
  config.gem "fastercsv", :version => '1.4.0'
  # ...
end

If you want to freeze the registered gems automatically under vendor/gems, just do:


rake gems:unpack

There is also the possibility to install them on any machine using this:


rake gems:install

Generally, I prefer to keep things in my repository, as I don’t want my deployment to fail because of network or routing issues.

The comments system is brand new - don't be afraid to comment!