33

I think I have tried all the suggestions I could find regarding this issue. Still not working for me.

When I try to bundle ...

$ bundle
...

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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
    --without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --with-pg
    --without-pg
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-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}/
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in
...
An error occurred while installing pg (0.17.1), and Bundler cannot
continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before
bundling.

Output from previous code...

$ which bundle
/Users/Loren/.rvm/gems/ruby-2.1.1@global/bin/bundle

$ which gem
/Users/Loren/.rvm/rubies/ruby-2.1.1/bin/gem

$ which psql
/usr/local/bin/psql

I tried to uninstall postgresql using Homebrew and reinstall and that didn't help.

I tried...

ARCHFLAGS="-arch x86_64" gem install pg

and that completes successfully but then when I run bundle I still get the same error.

I tried ...

gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config

and that didn't work.

I tried ...

gem install pg -v '0.17.1' -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.2/bin/pg_config

and that didn't work either.

I am not sure what else to try at this point. Thanks for any help.

Devin
  • 7,690
  • 6
  • 39
  • 54
halorium
  • 709
  • 1
  • 6
  • 8
  • You're probably missing the shared library. Do you have a `libpq.*.dylib` file anywhere? Normally these are in `/usr/lib`. – tadman Sep 02 '14 at 18:54

9 Answers9

101

My solution ended up at this

ARCHFLAGS="-arch x86_64" bundle install
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Josh Dean
  • 1,593
  • 2
  • 11
  • 17
  • 2
    My hero! This is the only thing that worked for me as well. 10.9.5 – Marina Martin Feb 01 '15 at 03:05
  • Same here. This worked for me on Yosemite 10.10.2. I've been trying other random incantations from around the net for days :-/ – Sophistifunk Feb 03 '15 at 09:35
  • hot d@mn...finally found one that worked...10.10.3 – bryanus Apr 24 '15 at 01:05
  • Finally something that currently works with Yosemite. Thank you! – JMP May 01 '15 at 20:45
  • Struggled on this error for 2 hours. finally found this solution. Worked for me on Yosemite. GREAT!!! – Rishabh Tayal Jun 30 '15 at 17:53
  • 1
    Saving lives left and right. Thank you. This fixed the issue for me on 10.10.3. I did have to install with homebrew before this step, rather than with bundle install. But after installing and linking via homebrew and executing `gem install pg` with the aforementioned flag, boom. Fixed. – justinraczak Sep 15 '15 at 19:53
  • This worked great. Just for convenience sake, is there a way to set ARCHFLAGS permently and not have to type "env ARCHFLAGS" every time you bundle install. If so add it to your answer. – jgleoj23 Mar 11 '16 at 16:45
  • Can you elaborate why this works (and it worked for me!) ? – Matheus Felipe Aug 04 '16 at 00:30
43

Based on this post's answer and it worked for me (Yosemite OSX 10.10), you can try the following:

$ sudo su

$ env ARCHFLAGS="-arch x86_64" gem install pg

You don't have to reinstall pg from homebrew.

Community
  • 1
  • 1
fruqi
  • 4,983
  • 4
  • 26
  • 32
12

sudo ARCHFLAGS="-arch x86_64" gem install pg
DID THE TRICK FOR ME...thanks for tip on a thread given by Jakob@github

My system: OSX 10.9.4, Ruby 2.0.0, local ( non-homebrew) Postgresql 9.3.5

Building native extensions.  This could take a while...
Successfully installed pg-0.17.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.17.1
unable to convert "\xCF" from ASCII-8BIT to UTF-8 for lib/pg_ext.bundle, skipping
Installing ri documentation for pg-0.17.1
1 gem installed
Makyen
  • 31,849
  • 12
  • 86
  • 121
susan
  • 121
  • 2
3

I uninstalled postgresql using home-brew ( I had used it to install postgresql before )

I installed the Postgres.app and this updated my PATH

I then had to stop the currently running postgresql db

I then was able to launch the Postgres.app and it started on port 5432

I then had to restart my terminal

Then I was able to run bundle and it worked.

halorium
  • 709
  • 1
  • 6
  • 8
2

In my particular instance I was trying to run bundle install on my first heroku app. I did all the items that @boobooninja listed (with slightly different paths, of course). What ended up working for me was a combination of two answers. I needed to

$ sudo su

$ env ARCHFLAGS="-arch x86_64" gem install pg -v '0.17.1' 

By adding the -v 0.17.1 and specifying the version needed by heroku I was able to complete my bundle and proceed.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Tek
  • 153
  • 1
  • 7
1

For ease of management and upgrading, etc. I have used the (PostgreSQL Application on my Mac with the following gem install (same as yours above).

gem install pg -- --with-pg-config=/Applications/Postgres__version__.app/Contents/MacOS/bin/pg_config

I have had no issues with this approach (versus a custom install or via Homebrew from which I have had a few problems).

craig.kaminsky
  • 5,588
  • 28
  • 31
1

Please make sure that you have the 'libpq-dev' package installed on your system

So try installing libpq-dev:

   for Ubuntu systems: sudo apt-get install libpq-dev
   on RHEL systems: yum install postgresql-devel
   for Mac: brew install postgresql

Then install pg gem

   $ gem install pg -v '0.17.1'
   $ bundle
Abhi
  • 3,361
  • 2
  • 33
  • 38
1

For me, the trick was to re-link Postgres 9.3.0

brew link postgresql
futbolpal
  • 1,388
  • 2
  • 13
  • 19
0

If you want to still be able to add gem 'pg' to your gemfile and use bundle install, and you know PostgreSQL and libpq-dev are installed (which I believe both should be since OS X ships with PostgreSQL) you need only tell your $PATH where to find pg_config. Try this:

$ ln -s /Library/PostgreSQL/9.1/bin/pg_config /usr/local/bin/pg_config

Make sure to replace 9.1 with whatever PostgreSQL version you have installed. And make sure wherever you're creating the link is in your $PATH. Once that's done, run bundle install to install the pg gem.

Gray Kemmey
  • 976
  • 8
  • 12