How can I pass a parameter for gem installation when I run bundle install?

ben picture ben · Mar 2, 2011 · Viewed 19.3k times · Source

I added the pg gem to my gemfile

gem 'pg'

When I run bundle install, I get this error:

Installing pg (0.10.1) with native extensions /Users/ben/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/Users/benhartney/.rvm/rubies/ruby-1.9.2-p0/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.

It seems I need to pass in this config parameter

 --with-pg-config=/path/to/pg_config

How can I do this when I use bundle install?

Answer

idlefingers picture idlefingers · Mar 2, 2011

You need to set a build config option like so:

bundle config build.pg --with-pg-config=/path/to/pg_config

More info can be found in the bundle config man page