74

当我运行时(以 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...
#-> 

当我运行捆绑安装时:

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.

我在 /usr/pgsql-9.1/include/libpq-fe.h 中安装了 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。

4

18 回答 18

188

您是否尝试过在运行之前运行它bundle install

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

http://bundler.io/v1.3/bundle_config.html

于 2012-02-10T21:32:55.050 回答
21

如果有人使用 macports 安装 postgres 并且在找到他们的 pg_config 时遇到问题,试试这个:

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

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

于 2012-04-23T08:21:42.690 回答
14

如果您不确定您的 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

于 2016-02-02T05:42:04.027 回答
7

有同样的问题,通过安装 libpq-dev 解决。

参考:https ://bitbucket.org/ged/ruby-pg/issue/83/help-gem-install-pg-failed-on-opensuse-103

于 2013-01-22T16:37:18.590 回答
6

复制粘贴:

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

于 2016-12-08T16:31:36.530 回答
4

如果您安装了 pg_config 但它不在任何路径中,您可能会收到此错误。您可以将它添加到 ~/.bashrc 中的 PATH 环境中。

例如。

export PATH=${PATH}:/usr/pgsql-9.2/bin
于 2013-01-14T16:35:47.740 回答
4

Postgres gem 找不到 Postgres 配置文件。你需要告诉它它在哪里。在我看来,最令人愉快的解决方案是跳过 Brew 和 MacPorts,只使用 Postgres 应用程序。从这里下载并安装:

http://postgresapp.com/

现在将 bin 文件夹添加到您的路径:

PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

您可能还希望将其添加到您的 ~/.bash_profile

现在安装gem:

gem install pg

它应该顺利进行。

于 2013-11-05T14:26:32.780 回答
4

我在 Mac 上,我使用 Homebrew,所以为了解决这个问题,我刚刚用 brew 安装了 postgresql:

brew install postgresql

然后安装gem。

于 2014-11-20T07:18:16.347 回答
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 用户解决这个问题。

于 2013-01-29T20:38:27.807 回答
2

试试这个:

yum install libpqxx-devel

它适用于 Postgr9.2。

于 2013-06-01T21:22:31.057 回答
2

我正在使用 Arch Linux,并且遇到了类似的问题。使用sudo pacman -S libpqxx并重新运行,然后安装 pg gem,然后bundle install再次运行,这次终于成功了!

于 2015-03-26T20:07:11.400 回答
2

一些关于 UBUNTU 的案例

sudo apt-get install libpq-dev

在 CentOS 7 上

sudo yum install postgresql-devel

然后

bundle install

这对我有用。

于 2018-08-02T20:15:55.347 回答
1

链接建议使用:

gem install pg --pre

我无法pg gem安装好几天,但这种方法终于对我有用。希望这会有所帮助。

于 2016-01-23T04:32:03.433 回答
1

你什么时候在 Mac 上使用 postgresapp,阅读http://postgresapp.com/documentation/cli-tools.html文档并配置你的 $PATH。在此之前尝试再次运行捆绑安装。

于 2016-03-22T02:44:17.317 回答
0
gem install pg -v '0.17.1'

为我做了诀窍。

于 2015-03-19T05:12:16.183 回答
0

确保您已安装 postgress。如果不先安装它。以终端为例。

brew install postgresql

在那次运行之后

bundle install
于 2017-05-25T14:10:11.573 回答
0

在 OSX 中,首先安装 pg:

brew install postgresql

第二,做gem安装:

gem install pg --source 'https://rubygems.org/'

然后你可以运行bundle install

于 2019-01-07T16:16:16.400 回答
-1

我正在使用 mac,不想在本地安装 postgresql。

安装libpq和设置捆绑器配置对我有用。

参考链接

于 2019-05-24T07:36:02.477 回答