JavaEar 专注于收集分享传播有价值的技术资料

Can't bundle Postgresql

When trying to run bundle install I get the following error

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/seque1990/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pg-0.18.4/ext
/Users/seque1990/.rbenv/versions/2.2.2/bin/ruby -r ./siteconf20160117-46131-1dmnnnq.rb extconf.rb --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config
Using config values from /opt/local/lib/postgresql91/bin/pg_config
sh: /opt/local/lib/postgresql91/bin/pg_config: No such file or directory
sh: /opt/local/lib/postgresql91/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:

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


extconf failed, exit code 1

Gem files will remain installed in /Users/seque1990/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pg-0.18.4 for inspection.
Results logged to /Users/seque1990/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/pg-0.18.4/gem_make.out

After getting that I did brew install postgresql but it tells me that it is already installed but not linked.

Then I tried brew link postgresql but it tells me:

Error: Could not symlink share/man/man3/SPI_connect.3 /usr/local/share/man/man3 is not writable.

Not sure how to proceed. :(


  1. If your using ubuntu machine then,

    sudo apt-get install postgresql
    sudo apt-get install libpq-dev

    And Then,gem install pg

    For oSx, you need to specify the pg_config path

    gem install pg -- --with-pg-config=`which pg_config`

    which pg_config gives you the file path where it is installed.