Last Updated: February 25, 2016
· dickeyxxx

Prevent gems from installing on Heroku

Need to prevent Heroku from installing some gems that are NOT in the test or development environments? For example, we use the memcached gem which won't compile on Heroku, but it still needs to run in some non-Heroku production environments.

If you want to do the same, first set a HEROKU environment variable:

heroku config:add HEROKU=true

Then add code like this in your Gemfile:

# Don't install these gems on Heroku
group ENV['HEROKU'] ? :test : :default do
  gem 'memcached', '1.3.2'

Now the environment variables are not normally enabled during slug compilation (when it installs the gems), but you can enable that!

Just do:

heroku labs:enable user-env-compile

For more info: