Getting the pg Gem Installed with

I use to run a local Postgres server while doing development work and it’s great. basically provides a completely contained pg server that’s ready to go out of the box — just launch the app and you’re good to go.

Unfortunately because it’s a self contained app things are installed in non-standard places.

More specifically, while installing the `pg` gem on a system I recently had it fail with this error:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

 /Users/mario/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
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.

Provided configuration options:

extconf failed, exit code 1

First off this error output is awesome. It clearly states that pg_config is missing and the solution is pretty simple — just pass in the path to’s pg_config.

I solved it by reinstalling the gem using:

➜ my_api git:(feature/add-ember) ✗ gem install pg -- --with-pg-config=/Applications/
Building native extensions with: '--with-pg-config=/Applications/'
This could take a while...
Successfully installed pg-0.17.1
1 gem installed

Bam! As you can see the gem installed successfully!

zomg! success kid w/o meme text!


  • Antonio

    How can i find the pg_config path?

    • Antonio… Looks like moved the location of pg_config!

      It’s now living in `/Applications/`. I’ve updated the post with the correct location.

  • I love you, man! You saved my day, thanks!!