Cannot install pg gem in Mavericks with Postgres.app
Asked Answered
L

8

76

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

Postgres.app is installed and running fine, but I cannot get the gem to work. I've done the following:

  1. Used the command 'env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config' from the Postgres.app documentation
  2. Updated Homebrew and installed the Apple GCC 4.2
  3. Installed the Xcode developer tools
  4. Updated my $PATH to reference both the Postgres.app bin and lib directories

All with no success. Here is the specific error message I receive:

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'd appreciate any help you can offer. Thanks!

Logan answered 26/11, 2013 at 17:55 Comment(1)
possible duplicate of Impossible to Install PG gem on my mac with MavericksChinch
L
262

You probably have the wrong path for --with-pg-config, check if it's actually there.

You can find the correct path to pg_config with:

find /Applications -name pg_config

In the latest Postgres.app Version the path is:

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config
Lumber answered 26/11, 2013 at 20:6 Comment(12)
Embarrassingly enough, that's it. After upgrading to the latest version of Postgres.app the path changed and I did not notice. Thanks!Logan
This was it for me too!Mckenziemckeon
Thanks for this! For some reason, on my installation I had to run $ gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config .Stuff
Newer Postgres.app installs might need you to use this command gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config .Bunko
@Sean: There is no 'bin' folder under Contents/MacOS on my system. Just a postgres executable file. The one Gabriel Osorio mentioned seems to be the right path (as of 9.3.4.1).Mcinnis
does anybody know why we need the '--' before the option?Flatter
For further reference, I just downloaded Postgres.app yesterday and my pg_config is located at Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config. One should be able to figure out where their pg_config is by using ls to look through the Applications/Postgres.app/Contents directory. See if you have /Contents/MacOS or /Contents/Versions...Sumter
every new ruby version I keep using this answer! thanks a million!More
The -- -- is important, must be a bug in pg.Sensualism
@BAR: no, the "--" is used to tell "gem install" to stop processing options, and anything after that (like "--with-pg-config") are build flags for how to build the specific gem. Check guides.rubygems.org/command-reference/#gem-installLumber
It looks like Postgres.app has been bumped up a version. I had to use gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_configEarlearla
Why is the extra set of -- needed for pass in arguments to gem install pg?Pusillanimous
P
16

In my case (running Postgres.app v9.3.4.2) it only seemed to work when prepending the environment architecture flags:

env ARCHFLAGS="-arch x86_64" gem install pg -- \
--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config 
Padang answered 22/7, 2014 at 20:41 Comment(2)
You can put the ARCHFLAGS in your .bash_profile (or equivalent) by including export ARCHFLAGS="-arch x86_64". For me, without this, PG doesn't work.Sumter
I'm using bundler and it took me a bit to figure out how to add this to a bundle command. You can use bundle config pg.build "....", see more at bundler.io/v1.3/man/bundle-config.1.htmlThorpe
J
14

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

  1. Install Xcode tools from the app store
  2. Open Xcode tools and accept the license
  3. Now run (hopefully a future-proofed 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 trouble, you can troubleshoot a bit by checking out the actual error in the mkmf.log which you can find by running (if using rvm):

cd ~/.rvm ; find . -name mkmf.log | grep pg
Jerold answered 2/3, 2014 at 19:6 Comment(3)
This is the correct path for the latest version of Postgres App.Kesha
The -- -- is important, must be a bug in pg.Sensualism
"latest" work as a version now, there is a symlink. That being said, I have a new M1 ship Mac and this does not work for me, I don't know why. I inspect the path and everything is there. Maybe that's because it does not expect a dylib for libpq.Deter
L
6

I was able to install pg with this command

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

I found my path by running

    sudo find / -name "pg_config"

and I Successfully installed pg-0.17.1

Languish answered 29/8, 2014 at 5:0 Comment(1)
It's easier to find the pg_config file with this command, so you don't have to search through all the files on your computer: $ find /Applications/Postgres.app/ -name "pg_config" Searching through /Library/ would work on your machine.Bates
T
3

adding the postgress bin dir to the path also does the trick. just add the bin to the pat like this. with recent installs the latest symbolic link makes sure that this path should be 'stable' for future version upgrades.

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
Tight answered 14/1, 2016 at 21:41 Comment(1)
Thanks, prepending this to gem install worked fine: PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin gem install pgJaime
W
2

To resolve this issue I installed postgres using homebrew using the following in the terminal window:

brew install postgres

Homebrew can be found here

http://brew.sh

Worship answered 3/12, 2013 at 20:42 Comment(2)
This does solve the issue, but it means installing a whole other postgres just for that one header file.Finochio
Yeah, don't do this if you're using Postgres.app. In fact, you should run brew uninstall postgres if it's there.Sumter
H
1

This worked for me:

gem install pg -- --with-pg-config=`which pg_config`
Harden answered 8/4, 2015 at 11:50 Comment(0)
S
1

For future reference, since a lot of us are posting new paths for the new version numbers:

Currently I'm seeing a symlink called latest in /Applications/Postgres.app/Contents/Versions/.

You should be able to just do:

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

And forget about the version number. This might not apply to every (older) version, but I myself was looking for a snippet I could save and reuse.

Stuff answered 3/11, 2017 at 16:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.