gem install pg --with-pg-config可以成功,但是bundle失败。

81

当我以root身份运行时

gem install pg -v '0.12.0' -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config

我得到了以下输出:
#-> gem instal pg -v '0.12.0' -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config
Building native extensions.  This could take a while...
Successfully installed pg-0.12.0
1 gem installed
Installing ri documentation for pg-0.12.0...
Installing RDoc documentation for pg-0.12.0...
#-> 

当我运行bundle install时:
Installing pg (0.12.0) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
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... 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:
--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=/usr/local/rvm/rubies/ruby-1.9.2-p290/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


Gem files will remain installed in /var/www/simpletrac/vendor/cache/ruby/1.9.1/gems/pg-    0.12.0 for inspection.
Results logged to /var/www/simpletrac/vendor/cache/ruby/1.9.1/gems/pg-0.12.0/ext/gem_make.out
An error occured while installing pg (0.12.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.12.0'` succeeds before bundling.

我安装了libpq-fe.h,路径为/usr/pgsql-9.1/include/libpq-fe.h。因此,我尝试执行以下操作:

gem install pg -v '0.12.0' -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config --with-pg-lib=/usr/pgsql-9.1/include/libpq-fe.h but still no go. 

任何帮助都会非常感激。
另外,我已经安装了postgresql91-devel和ruby-devel。运行的是CentOS 6。
18个回答

197

如果您正在使用MacOS + MacPorts,请查看Lester的帖子以获取解决方案。 - mxk
我也遇到了同样的错误,但是我使用的是MySQL数据库。请问应该用什么命令? - KK Patel
1
这似乎是MySql的答案:https://dev59.com/nG025IYBdhLWcg3wl3Am#9360181 - Johannes Fahrenkrug
2
在CentOS 6上运行得非常好!只需要在整个安装过程之前运行yum install postgresql-devel即可完全成功安装! - Andrea Salicetti
2
同时 --with-pg-dir=/usr/pgsql-<version> 处理配置和库。 - rdupz

22

如果有人使用了macports来安装postgres,却在查找pg_config时遇到问题,请尝试以下方法:

bundle config build.pg --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config

我希望这可以帮助某些人节省时间。干杯!


21

如果您不确定 pg_config 的位置,并且假设您在 Linux 或 Mac 上,您可以运行以下命令:

which pg_config

这将返回 /usr/pgsql-9.1/bin/pg_config

现在使用这个路径作为

bundle config build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config

我们已经准备好了,可以执行bundle install命令。


10

复制粘贴:

bundle config build.pg --with-pg-config=`which pg_config` && bundle

详情:

更多信息请访问:

首先要做的是确保Postgres附带的“pg_config”工具在您的路径中。如果不在路径中,或者路径中排在第一位的不是要构建的Postgres安装的工具,则可以使用“--with-pg-config”选项指定其路径。

来源: https://github.com/ged/ruby-pg/blob/1f274f68c16f1af1c642db1b9d3d28aef169dc84/ext/extconf.rb#L27


7

5

如果您安装了pg_config但未将其添加到任何路径中,则可能会出现此错误。您可以在~/.bashrc中将其添加到PATH环境变量中。

例如:

export PATH=${PATH}:/usr/pgsql-9.2/bin

这可能是从源代码安装而不是使用软件包管理器安装的结果吗?对我来说起作用了 - 只是好奇为什么会遇到这个问题。 - FantasticSponge

5

Postgres gem无法找到Postgres配置文件。您需要告诉它在哪里。在我看来,最好的解决方案是跳过Brew和MacPorts,直接使用Postgres应用程序。从这里下载并安装:

http://postgresapp.com/

现在将bin文件夹添加到您的路径中:
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

你可能希望将这个添加到你的~/.bash_profile中。
现在安装gem:
gem install pg

它应该顺利进行。


4

我使用Mac并且使用Homebrew,所以为了解决这个问题,我只需使用brew安装postgresql:

brew install postgresql

然后安装了gem。


3

我在OS X上遇到同样的问题,需要这样做才能解决:

export PATH=/opt/local/lib/postgresql84/bin/:$PATH

尽管我已经有了这个经验,但我还是必须去做它:

[user@foo ~] which psql84
/opt/local/bin/psql84

[user@foo ~] ls -altrh /opt/local/bin/psql84 
lrwxr-xr-x  1 root  admin    36B Dec  7 02:15 /opt/local/bin/psql84 ->  /opt/local/lib/postgresql84/bin/psql

我希望这能帮助其他Mac用户解决这个问题。

谢谢,我已经在 Mac Yosemite 上测试了这个解决方案。 - newguy

2

试试这个:

yum install libpqxx-devel

它可以与PostgreSQL 9.2一起使用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接