Freezing your Rails version/gems!

14 Jul
2009

Ever wondered what “freeze your gems” is all about?

Most rails app depend heavily on gems (rails itself is a gem!) and we somehow need to make sure that everything works together. And you really should care about this.

Update all your gems

sudo gem update

New gem updates may make backward incompatible changes that breaks the code. So freezing a gem puts it into the vendor folder of the application and will not updated on its own. Rails first looks into /vendor/rails before searching everywhere else for your gems.

Freeze your rails app

Happy us – there’s a rake task that does all the hard work!

rake rails:freeze:gems

Freezing now copies unpacks rails into this special folder.

There’s also a “rake rails:unfreeze” – command, but if you simply wanna freeze your updated rails gems, run the freeze-command again.

Manage your dependencies

To freeze your gems, you need to tell rails what you need. Therefore use the gem dependency feature of Rails 2.1+. Edit config/environment.rb

If you don’t know what you require, read the full list via gem list.

Rails::Initializer.run do |config|
...
# Require the latest version of haml
config.gem "haml"
config.gem "thoughtbot-factory_girl",
:lib    => "factory_girl",
:source => "http://gems.github.com"
...
end

You can require a specific version or the latest (omitting the :version parameter); custom sources are also possible via :source => (e.g. the gems.github.com stuff)

Now tell rake that you want to install those gems (they should be installed anyway)

rake gems:install

Freeze your gems

Next, we wanna freeze the gems too. The are copied into /vender/gems

rake gems:build
rake gems:unpack:dependencies

The build command makes the native extensions.

Get the list of your gems

rake gems

The ‘F’ shows your freezed gems.

Note

There are some gotchas however: Gems with native extensions(libxml…) can’t be frozen, as the OS code needs to live in the external OS.

Links

http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies

http://stackoverflow.com/questions/799416/whats-the-point-of-freezing-your-rails-version-gems

http://www.softiesonrails.com/2008/1/3/freezing-your-rails-application

Related posts:

  1. HowTo update rake 0.8.1 -> 0.8.4 on debian
  2. Rails + Google App Engine !?
  3. Rails has_many and dynamic conditions
  4. Demystifiying Rails Model attributes overriding
  5. Open Source iPhone Gems, Part 2

Comment Form

top

Switch to our mobile site