Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL gem for rails won't install, even when both home brew and app are installed

I have tried following this answer to get the gem to work, but it wont. I have my projects set up such that individuals projects have there own gems instead of all themes gems living in global space, and then I use binstubs to allow me to do things like bin/rails.

So all gems are installed to .bundle/gems/ for each project. the one that always gives me the toughest problems is posgresql. Lets go through the steps.

So I run:

bundle

It explodes stating:

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

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Using config values from /Applications/Postgres.app/Contents/Versions/9.3/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
    --enable-windows-cross
    --disable-windows-cross
    --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}/
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in /Users/Adam/Documents/Rails-Projects/AisisPlatform/.bundle/gems/gems/pg-0.18.1 for inspection.
Results logged to /Users/Adam/Documents/Rails-Projects/AisisPlatform/.bundle/gems/gems/pg-0.18.1/ext/gem_make.out
An error occurred while installing pg (0.18.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.1'` succeeds before bundling.

So then, because I have the home brew version installed at 9.4.0 and the posgresql.app installed I then did:

bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

Followed by, because I use 18.1

gem install pg -v '0.18.1'

And I got:

Building native extensions.  This could take a while...
Successfully installed pg-0.18.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.18.1
Done installing documentation for pg after 2 seconds
1 gem installed

From there I tried bundle Well we are back to square one because even though the gem installed - I get the EXACT same error.

Is this because I am installing the pg gem globally and not locally? How can I fix this? This one project, every time I have to do a rm -rf .bundle/gems Causes this exact issue over and over again.

I should point out I get the same error even if I use the home brew psql pg_config Do all the steps above, just with home brew version, same results.

like image 232
TheWebs Avatar asked Jan 19 '15 20:01

TheWebs


2 Answers

At the end of the day it was:

ARCHFLAGS="-arch x86_64" bundle install

that worked for me.

reason being:

by default it tries to compile a universal binary, which apparently fails... so that environment variable makes it only compile the x86 version which is all you need

you can add this line to your ~/.profile or similar: export ARCHFLAGS="-arch x86_64"

For further reading see: This README for OSX

like image 189
TheWebs Avatar answered Oct 20 '22 04:10

TheWebs


Make sure Postgres is installed on your computer first

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

Then run bundle install

like image 25
Minemag Avatar answered Oct 20 '22 04:10

Minemag