简体   繁体   中英

cannot install pg gem, checking for PQconnectdb() in -lpq… no

I'm trying to develop in Ruby on Rails using PostgreSQL locally, so I'm trying to install the pg gem. On Ubuntu 12.04. In terminal, I typed in:

gem install pg -v '0.12.2'

Which throws the following error:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /home/troyshu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/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
    --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=/home/troyshu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
    --with-pg
    --without-pg
    --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-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in /home/troyshu/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.1 for inspection.
Results logged to /home/troyshu/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.1/ext/gem_make.out

Interestingly, adding a sudo to the command works:

$ sudo gem install pg -v '0.12.2'
Building native extensions.  This could take a while...
Successfully installed pg-0.12.2
1 gem installed

Btw I had to run "sudo apt-get install ruby1.9.1-dev" to get the above command to work. But I still can't do any development because "bundle install" will not work (and keeps telling me to run 'gem install pg -v '0.12.2')

I have a feeling "gem install pg" is getting tripped up at

checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no

but, as a complete noob to Ubuntu and RoR, I have no idea why. Maybe my search skills stink too, because I haven't been able to find a solution to my particular case. Hopefully there's a fix?

Thanks!

Related: gem install pg can not bind to libpq . Please check your mkmf log and look for errors with libssl. I had the exact same problem. I had installed libpq-dev and double checked pg_config. It seems that the gem had found the libpq-dev header files but had failed to link with libpq. It turned out that the packages that rvm has installed for ssl were somehow interfering with the packages installed through libssl-dev.

Based on the error message you posted, it looks like you don't have libpq-dev installed. Try apt-get install libpq-dev (with sudo if you're not root ) and then installing the gem.

Since you're using RVM, if you ever have to use sudo to install a gem, you're doing it wrong. sudo installs the gem for using the system's Ruby, not the Ruby you installed using RVM.

我找到了一个奇怪的解决方案,但它对我有用,而不是其他所有建议:

mv ~/.rvm/usr/lib ~/.rvm/usr/lib_rvm 

if sudo works and a standard user does not, this suggests either that it is finding some set of libraries and header files somewhere which are not found as the other user or that there is actually a permissions issue that is not getting properly handled somewhere else. You could probably use strace to find the root of the problem if you want.

However, I think the saner solution is to recognize you probably need root access to install a lot of things like this anyway, and so if it were my system I would live with it.

I had a similar issue, with a failed bundle install :

Installing pg 0.17.1 with native extensions

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

...

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.

but with gem install pg -v '0.17.1' .

I could successfully install the gem, but the bundle would still fail.

I fixed it by changing the pg bundle configurations:

  1. Check the pg configs:

    $ which pg_config returns:

    /usr/local/bin/pg_config

  2. Check current bundle build options for pg

$ bundle config build.pg

  1. If not the value returned by which pg_config ,

$ bundle config build.pg --with-pg-config=/usr/local/bin/pg_config

Now try to bundle install !!!!

For me, the only thing that worked was installing rvm via the instructions on rvm's website: https://rvm.io . I was able to get it working on Ubuntu 14.04.

The full command list at this date:
sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Make sure you are in a downloadable directory then run:
\\curl -sSL https://get.rvm.io | bash -s stable

When you do sudo gem install pg the gem is installed wherever ruby and postgresql are installed; when you do gem install pg the gem is installed in your home directory (see your messages!). So, you need to do sudo bundle install blah-blah-blah for all your gems given the way you are working locally. There are other options, of course, like RVM, which I do not use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM