Ruby on Rails, programming, and SEO
Check out my articles about Ruby on Rails, programming, and SEO. Weekly updates? Subscribe to my feed.

Deploying gems using Capistrano

How to deploy gems from your Ruby on Rails application through Capistrano.

Update for Rails 3: Rails 3 and Bundler: Deploying gems using Capistrano

Thought I’d share this because I had a lot of trouble figuring out how and where to run the “rake gems:install” when deploying with Capistrano. I wanted it to automatically deploy the gems when I call “cap deploy:migrations” – this is done by installing the gems right after update_code, like this:

# config/deploy.rb
after "deploy:update_code", "gems:install"

namespace :gems do
  desc "Install gems"
  task :install, :roles => :app do
    run "cd #{current_release} && #{sudo} rake gems:install"
  end
end

Some of the examples I’ve seen use “cd #{current_path}” but I don’t think this would work as the “current” symlink hasn’t been updated at the time the “update_code” task is run. That’s why I use “current_release”.

Also others use “rake RAILS_ENV=production gems:install” but I can’t see why you should have to use RAILS_ENV here. If I’m wrong, please correct me.

Some of the links I found when trying to get this to work:

Related posts

Tags: , , ,

8 comments

  1. Dave Lyons says:

    Hey mate, thanks for posting this – it was the only snippet I could find for installing gems that actually works!

    Cheers

  2. Justin Powers says:

    FYI – I just implemented this, and I inserted RAILS_ENV=production into mine, simply because I have gems that are used on my deployment machines that I do not want installed in my production machines (ie ruby-debug). I only have those gems required in my production environment.

  3. lassebunk says:

    @Justin: Thanks for telling – could be useful for others too.

  4. Tommy says:

    Worked perfectly first try. Thank you so much!

  5. lassebunk says:

    @Tommy: Nice – good thing you could use it :-)

  6. Lucas Watson says:

    my favorite gemstone is none other than diamond. the most expensive and priceless gemstone ever.`.,

  7. gemstones are expensive but when you give a ring with gemstone to your girlfriend, she would really like it `~~

  8. `.- I am really thankful to this topic because it really gives up to date information :”`

Leave a comment

Fork me on GitHub