Postgresapp: gem install pg ... fails

Created on 26 Apr 2014  路  17Comments  路  Source: PostgresApp/PostgresApp

Most helpful comment

Did you try adding Postgres.app's bindir to your $PATH?

Just add a line like the following to .bash_profile:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin

All 17 comments

I wanted to setup a postgresql database access into my rails app.

  • rails : 4.0.0
  • ruby: 2
  • postgresql: 9.4.3.1

The installer complains it's missing some dependencies. Any idea ?

$ sudo gem install pg -v '0.17.0' -- --with-pg-dir=/Applications/Postgres.app/Contents/Versions/9.3/
Building native extensions with: '--with-pg-dir=/Applications/Postgres.app/Contents/Versions/9.3/'
This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-dir=/Applications/Postgres.app/Contents/Versions/9.3/

checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/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
--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 /Library/Ruby/Gems/2.0.0/gems/pg-0.17.0 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out

It seems that pg_config isn't found.

Two possible solutions:

  1. Set up your PATH as described in the docs so that pg_config is found (type which pg_config to make sure it works)
  2. Try --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

If the build later fails because clang from XCode 5.1 gets unexpected arguments, try ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install pg

Thanks for your rapid answer, but still no cigar 馃槉

It seems it's missing some libraries...

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Fetching: pg-0.17.1.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
MacBook-Air:app herbert$ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Building native extensions with: '--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config'
This could take a while...
ERROR: Error installing pg:
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
--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 /Library/Ruby/Gems/2.0.0/gems/pg-0.17.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/pg-0.17.1/ext/gem_make.out

Did you try adding Postgres.app's bindir to your $PATH?

Just add a line like the following to .bash_profile:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin

Also, try specifying $ARCHFLAGS:

sudo ARCHFLAGS="-arch x86_64" gem install pg

Hourra :-D

Give the man a cigar. It worked.

Thanks a lot

thanks

@jakob Thanks for the solution, worked perfect for me.

I spent the past two days all over the web trying to solve this same issue but this solved it instantly. Many thanks!

It didn't work for me and finally I tried this on OS X and it worked! :)

brew install postgresql

@jakob YUS I have been looking this stuff up for HOURS!

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin

Postgres.app is missing from my application folder. @jakob I having the same error as the person who started the thread.

@YonasBerhe This thread only deals with Postgres.app. If you don't use Postgres.app, I can't help you.

Please also note that the path for the current version is
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin (note the major version number in the path, ie. 9.4 instead of 9.3)

Can anyone say me how it works in windows? i tried gem install pg , gem install pg --with-pg-config="path to pg_config.exe" & also ARCHFLAGS="-arch x86_64" gem install pg . but still it doesnt works. @jakob

@adityanagla1996 I'm sorry, I can't help with installation on Windows.

I am having this same issue when trying to install with $ bundle install

additional messaging:

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.3/usr/bin/$(RUBY_BASE_NAME)
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --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}/lib
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/tyler/Desktop/pepper/pepperapi/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-17/2.3.0/pg-1.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/tylerharrington/Desktop/pepper/pepperapi/vendor/bundle/ruby/2.3.0/gems/pg-1.0.0 for inspection.
Results logged to /Users/tyler/Desktop/pepper/pepperapi/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-17/2.3.0/pg-1.0.0/gem_make.out

An error occurred while installing pg (1.0.0), and Bundler cannot continue.
Make sure that `gem install pg -v '1.0.0'` succeeds before bundling.

However the command listed above works fine:

$ sudo ARCHFLAGS="-arch x86_64" gem install pg -v '1.0.0'

It appears the context of bundler is breaking something...

@imechemi Thanks Man Worked for me

Was this page helpful?
0 / 5 - 0 ratings