Excluding Dev and Test Gems from Heroku

Update: Check out our newer blog article that shows a better method of excluding dev and test gems from heroku.

Heroku is awesome. Bundler is awesome. Combining the two… not always awesome. Are you getting this when pushing to Heroku?

You have modified your Gemfile in development but did not check
the resulting snapshot (Gemfile.lock) into version control
...
Heroku push rejected, failed to install gems via Bundler

Try this workflow:

  • Ensure Gemfile.lock is in .gitignore
  • Ensure your :development and :test groups in Gemfile are surrounded by: if RbConfig::CONFIG['host_os'] =~ /darwin/ && false
  • Run bundle
  • Run git add Gemfile.lock
  • Remove the && false from the Gemfile
  • Run git add Gemfile

That’s it! You should be good to go. Repeat steps 2-6 every time you need to modify the Gemfile outside the RbConfig::CONFIG['host_os'] block.

A forthcoming blog post will explain how and why this works.


Category: Development
Tags: Tutorial