Freezing your Rails when you deploy shared

Posted by David December 22, 2005 @ 09:03 PM

If you’re running a Ruby on Rails application on a shared host, it’s super-double-plus recommended to freeze your Rails. Freezing your Rails means putting the framework into vendor/rails instead of floating with whatever gems that are installed on the host. Because if you do so, you’ll automatically be upgraded when they are. Not a great thing for a production application to have forced upon itself.

The great news is that this is silly simple. If you’re running 0.14.x or newer, you can simple do rake freeze_gems, and the current gems the system is used are unpacked into vendor/rails. Now the host can update as silly as it wants without affecting your application.

Posted in Tricks | 8 comments

Comments

  1. topfunky on 22 Dec 21:51:

    Also see my rake task for freezing your third-party gems as well.

  2. Rube on 22 Dec 23:27:

    I do this on dreamhost, but you can’t use config.frameworks to remove :active_record (it tries to reference a class that hasn’t been loaded, ‘Base’). So you if you want to do this on an app with no database, you’ll need to edit initializer.rb and comment out the establish_connection line.

  3. Sean on 23 Dec 01:05:

    Is it possible to rollback the freeze using rake? As in this scenario:

    1) Have development code checked out. 2) Run freeze_gems rake task to copy rails gems into vendor/rails. 3) Deploy application to production host. 4) Run ‘unfreeze_gems’ to remove rails gems from vendor/rails and continue with development using development machine’s gems.

  4. David Heinemeier Hansson on 23 Dec 05:54:

    Sean: “rake unfreeze_rails”

  5. riffraff on 24 Dec 02:44:

    sorry, but I don’t understand: why don’t you simply use require_gem with an exact version? The main point of rubygems is to be able to have multiple versions available at the same time.

  6. riffraff on 24 Dec 02:46:

    sorry, but I don’t understand: why don’t you simply use require_gem with an exact version? The main point of rubygems is to be able to have multiple versions available at the same time.

  7. Louis on 24 Dec 04:37:

    In a shared hosting environment, you can’t install the correct versions of gems. And many hosts don’t realise that multiple versions may be required – or that it’s even possible to have them all installed at the same time.

    The safest route is to include everything you need, in one folder, for quick and painless “xcopy” deployment.

    And thanks for the time-saving “freeze-other-gems” script, topfunky. Very useful :)

  8. sathish on 07 Jan 09:05:

    On Windows XP Freezing to the gems for Rails 1.0.0 rm -rf vendor/rails mkdir -p vendor/rails The filename, directory name, or volume label syntax is incorrect. The filename, directory name, or volume label syntax is incorrect. The filename, directory name, or volume label syntax is incorrect. The filename, directory name, or volume label syntax is incorrect. The filename, directory name, or volume label syntax is incorrect. The system cannot find the path specified. rake aborted! undefined method `to_str’ for nil:NilClass