Search code examples
ruby-on-railsherokurubygemsbundlepg

Error with gem pg shouldn't happen locally, only in production, why is bundle installing it?


I have a Ruby on Rails application and am just starting to deploy it to Heroku.

The Heroku quick start guide says to include the pg gem for your database on production. OK, this came up the last time I deployed to Heroku, and I solved it with the following:

group :production do
  gem 'pg'
end

However, this time around, when I try to "bundle install" or "bundle update" my app locally, it is for some reason trying to install pg, even though I explicitly told it to only use pg in production! Any reason why this is, and what can I do to fix it? Thanks!

Installing pg (0.13.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Solution

  • Try running

    bundle install --without production
    

    This will prevent production gems being bundled, and the setting will stick for normal bundle commands until the next time your use the --without parameter.