2

We run Unicorn on Heroku in production but use Webrick in development on a local machine. We are unable to install Unicorn on the local machine.

Is it possible to have Rails load the Unicorn gem only in production? Right now, our solution is to comment out the Unicorn gem when running the app locally and uncomment the gem when pushing to Heroku.

We're on Rails 3.2.12.

Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.2.12'
gem 'jquery-rails'


# # =========================================================================================
# 
# #=========================================================================================
gem 'mongo'
gem 'mongo_mapper'
gem 'plucky'
gem 'bson_ext'
gem 'bson'
gem 'newrelic_rpm'
gem 'rpm_contrib'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails', '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

Thanks!

Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • As long as your Gemfile looks right and you have bundled right, Unicorn should be available locally as well. Can you check if Unicorn is under any group in the Gemfile? – membLoper Dec 30 '13 at 02:31
  • @membLoper, updated with our Gemfile – Crashalot Dec 30 '13 at 02:52
  • The reason we can't use Unicorn is because our dev machine is a Windows machine right now, and Unicorn doesn't work on Windows. – Crashalot Dec 31 '13 at 03:13

1 Answers1

2

Is it possible to have Rails load the Unicorn gem only in production? Right now, our solution is to comment out the Unicorn gem when running the app locally and uncomment the gem when pushing to Heroku.

Yes, it is possible by the use of groups in Gemfile. Update your Gemfile like follows for the unicorn gem in production only:

# Gemfile
group :production do 
  gem 'unicorn'
end

Since WEBrick is the default web server for rails apps, you wouldn't need to specify anything for development group.

Running bundle install after the Gemfile update will still install the production gems. This is definitely a good thing to do as you want to make sure the gems you are planning to use in production work correctly with your application from the development phase of project.

To skip installation of production group gems:

bundle install --without production

A point to be noted about the --without production option is that the subsequent calls to bundle install and bundle update are also going to skip installing and updating production gems. To disable this you'd need to remove the lineBUNDLE_WITHOUT: production from your app_root/.bundle/config:

# app_root/.bundle/config

BUNDLE_WITHOUT: production
vee
  • 38,255
  • 7
  • 74
  • 78
  • hmm, the group didn't seem to work. when we run "rails s" in development, it's displaying an error about not finding the unicorn gem. anything else? – Crashalot Dec 31 '13 at 02:13
  • 1
    Search for reference to unicorn in your `Gemfile` and `Gemfile.lock`. You might also need to do `bundle clean --force` then `bundle install --without production`. Give these a try, they might help! – vee Dec 31 '13 at 04:15
  • still doesn't work. does this work for rails 3.2.12? – Crashalot Jan 07 '14 at 00:28
  • @Crashalot, sorry for the late reply. Wanted to let you know that this is tested in `Rails 3.2.16`. – vee Feb 09 '14 at 03:50