简体   繁体   English

无法安装pg gem,请在-lpq中检查PQconnectdb()...否

[英]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. 我试图在本地使用PostgreSQL在Ruby on Rails中进行开发,所以我试图安装pg gem。 On Ubuntu 12.04. 在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可以工作:

$ 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. 顺便说一句,我必须运行“ sudo apt-get install ruby​​1.9.1-dev”才能使上述命令正常工作。 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') 但是我仍然无法进行任何开发,因为“捆绑安装”将不起作用(并且一直告诉我运行'gem install pg -v'0.12.2')

I have a feeling "gem install pg" is getting tripped up at 我感觉“ gem install pg”被绊倒了

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. 但是,作为Ubuntu和RoR的完整入门者,我不知道为什么。 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 . 相关: gem install pg无法绑定到libpq Please check your mkmf log and look for errors with libssl. 请检查您的mkmf日志并查找libssl错误。 I had the exact same problem. 我有同样的问题。 I had installed libpq-dev and double checked pg_config. 我已经安装了libpq-dev并仔细检查了pg_config。 It seems that the gem had found the libpq-dev header files but had failed to link with libpq. gem似乎找到了libpq-dev头文件,但未能与libpq链接​​。 It turned out that the packages that rvm has installed for ssl were somehow interfering with the packages installed through libssl-dev. 原来,rvm为ssl安装的软件包在某种程度上干扰了通过libssl-dev安装的软件包。

Based on the error message you posted, it looks like you don't have libpq-dev installed. 根据您发布的错误消息,您似乎没有安装libpq-dev Try apt-get install libpq-dev (with sudo if you're not root ) and then installing the gem. 尝试apt-get install libpq-dev (如果不是root使用sudo ),然后安装gem。

Since you're using RVM, if you ever have to use sudo to install a gem, you're doing it wrong. 由于您使用的是RVM,因此如果您必须使用sudo来安装gem,那么您做错了。 sudo installs the gem for using the system's Ruby, not the Ruby you installed using RVM. sudo将安装gem以使用系统的Ruby,而不是使用RVM安装的Ruby。

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

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. 如果sudo起作用而标准用户不起作用,则表明它是在某处找到一组库和标头文件,而该组库和头文件是其他用户所找不到的,或者实际上存在权限问题,在其他地方未得到正确处理。 You could probably use strace to find the root of the problem if you want. 如果需要,可以使用strace查找问题的根源。

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. 但是,我认为更明智的解决方案是识别出您可能需要root用户访问权限才能安装很多类似的东西,因此,如果它是我的系统,我将与之兼容。

I had a similar issue, with a failed bundle install : 我有一个类似的问题, 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' . 但是使用gem install pg -v '0.17.1'

I could successfully install the gem, but the bundle would still fail. 我可以成功安装gem,但是捆绑包仍然会失败。

I fixed it by changing the pg bundle configurations: 我通过更改pg bundle配置来修复它:

  1. Check the pg configs: 检查pg配置:

    $ which pg_config returns: $ which pg_config返回的$ which pg_config

    /usr/local/bin/pg_config

  2. Check current bundle build options for pg 检查pg当前包构建选项

$ bundle config build.pg

  1. If not the value returned by which pg_config , 如果不是which pg_config返回的值,

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

Now try to bundle install !!!! 现在尝试bundle install !!!

For me, the only thing that worked was installing rvm via the instructions on rvm's website: https://rvm.io . 对我而言,唯一有效的方法是按照rvm网站上的说明安装rvmhttps ://rvm.io。 I was able to get it working on Ubuntu 14.04. 我能够在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; 当您执行sudo gem install pg ,gem会安装在ruby和postgresql所安装的地方; when you do gem install pg the gem is installed in your home directory (see your messages!). 当您执行gem install pg ,gem会安装在您的主目录中(请参阅消息!)。 So, you need to do sudo bundle install blah-blah-blah for all your gems given the way you are working locally. 因此,鉴于您在本地工作的方式,您需要为所有gem执行sudo bundle install blah-blah-blah There are other options, of course, like RVM, which I do not use. 当然,还有其他选项,例如RVM,我不使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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