Cannot install pg gem in Mavericks using Postgres.app

I am trying to install pg gem for use with Postgres.app on my local machine. I'm running the mavericks.

Postgres.app is installed and working fine, but I can’t get the stone to work. I have done the following:

  • The env command is used ARCHFLAGS = "- arch x86_64" gem install pg - --with-pg-config = / Applications / Postgres.app / Contents / MacOS / bin / pg_config 'from the Postgres.app documentation
  • Updated Homebrew and installed Apple GCC 4.2
  • Xcode Developer Tools Installed
  • Updated my $ PATH for link to bin and lib Postgres.app directories.

All without success. Here is the specific error message I get:

Building native extensions with: '--with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config' This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /Users/Brian/.rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config Using config values from /Applications/Postgres.app/Contents/MacOS/bin/pg_config sh: /Applications/Postgres.app/Contents/MacOS/bin/pg_config: No such file or directory sh: /Applications/Postgres.app/Contents/MacOS/bin/pg_config: No such file or directory 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: --with-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/Users/Brian/.rvm/rubies/ruby-2.0.0-p353/bin/ruby --with-pg --without-pg --with-pg-config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include --with-pg-lib --without-pg-lib=${pg-dir}/ 

I would appreciate any help you can offer. Thank!

+62
ruby-on-rails postgresql osx-mavericks pg macos
Nov 26 '13 at 17:55
source share
8 answers

You probably have the wrong path for --with-pg-config , check if it is really there.

You can find the correct path to pg_config with:

 find /Applications -name pg_config 

In the latest version of Postgres.app, the path is:

 gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config 
+227
Nov 26 '13 at 20:06
source share

In my case (running Postgres.app v9.3.4.2), it worked only when adding environment architecture flags:

 env ARCHFLAGS="-arch x86_64" gem install pg -- \ --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config 
+16
Jul 22 '14 at 20:41
source share

Being on a brand new mac, here is what I had to do:

  • Install Xcode Tools from the App Store
  • Open Xcode Tools and Accept License
  • Now run (hopefully a future command):

    version=$(ls /Applications/Postgres.app/Contents/Versions/ | tail -1) gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/$version/bin/pg_config .

If you have problems, you can fix the problem a bit by checking the actual error in mkmf.log, which you can find by doing (if rvm is used):

 cd ~/.rvm ; find . -name mkmf.log | grep pg 
+13
Mar 02 '14 at 19:06
source share

I managed to install pg with this command

  gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config 

I found my way by running

  sudo find / -name "pg_config" 

and I have successfully installed pg-0.17.1

+5
Aug 29 '14 at 5:00
source share

To solve this problem, I installed postgres using homebrew using the following in a terminal window:

 brew install postgres 

Homepage is here.

http://brew.sh

+2
Dec 03 '13 at 20:42
source share

This worked for me:

 gem install pg -- --with-pg-config=`which pg_config` 
+1
Apr 08 '15 at 11:50
source share

adding the postgress bin path to the path also does the trick. just add basket to stalemate like this. with a recent install of the latest symlink, make sure this path is "stable" for future version updates.

 export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin 
+1
Jan 14 '16 at 21:41
source share

In the future, as many of us are publishing new ways for new version numbers:

Currently, I see the latest /Applications/Postgres.app/Contents/Versions/ in /Applications/Postgres.app/Contents/Versions/ .

You should be able to:

 $ gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config 

And forget about the version number. This may not apply to each (older) version, but I myself was looking for a fragment that I could save and reuse.

0
Nov 03 '17 at 16:23
source share



All Articles