69

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?

Arnaud Meuret
  • 985
  • 8
  • 26
ben
  • 29,229
  • 42
  • 124
  • 179

5 Answers5

91

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 command documentation

Arnaud Meuret
  • 985
  • 8
  • 26
idlefingers
  • 31,659
  • 5
  • 82
  • 68
  • Awesome! Looks like this stores it in the config and will be used in the future. Thanks! – Josh Mar 28 '12 at 20:07
16

Run 'bundle config' before 'bundle install' to set the parameters, i.e.:

bundle config build.pg --with-pg-config=/path/to/pg_config
bundle install
Mark
  • 461
  • 3
  • 6
9

with Rails3 and PostgreSQL. I do like this

>rails new test_app -d postgreSQL
>cd test_app
>mkdir .bundle
>echo "BUNDLE_BUILD__PG: --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config" > .bundle/config
>bundle install

so you can keep config in source control.

for user's profile

bundle config build.pg --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config

this will create ~/.bundle/config file.

Jirapong
  • 24,074
  • 10
  • 54
  • 72
  • Unless it's only you working on the app and every place it may run has the same path to the postgres config, you shouldn't check this kind of thing into your scm. It is environment-specific, and might not be the same for every machine. That's why, generally, it's best to do it per-user. – idlefingers Mar 02 '11 at 21:32
  • Idlefingers, yes. that's right. so that why i gave two options. your/his choice, what best for. :-) – Jirapong Mar 03 '11 at 03:11
1

The damn problem almost killed me, fortunately, I fixed.

You can

ARCHFLAGS="-arch x86_64" gem install pg -v '0.20.0' -- --with-pg-config=/path/to/pg_config

my path is ARCHFLAGS="/Applications/Postgres.app/Contents/Versions/10/bin/pg_config

Here is the guarantee you installed the pg

you have to make sure your command "bundle install" goes here as well. especially, if you have multiple pg versions.

so we have to set the bundle config before bundle

bundle config build.pg --with-pg-config=/pathbin/pg_config

summary:

$ ARCHFLAGS="-arch x86_64" gem install pg -v '0.20.0' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/10/bin/pg_config
$ bundle config build.pg --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config
$ bundle install
`
TorvaldsDB
  • 766
  • 9
  • 8
0

If you're using Ruby 2.x and up, then thrift 0.9.0 can't build with it. see https://issues.apache.org/jira/browse/THRIFT-2219. Thrift 0.9.2 is fixed.

Try installing: gem install rbhive -v 1.0.3.pre

0bserver07
  • 3,390
  • 1
  • 28
  • 56