postgresql gem install pg --with-pg-config 工作,捆绑失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9234960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:19:23  来源:igfitidea点击:

gem install pg --with-pg-config works, bundle fails

postgresqlrubygemsbundlerpg

提问by YuKagi

WhenI run (as root)

当我运行时(以 root 身份)

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

I get the following output:

我得到以下输出:

#-> 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...
#-> 

When I run bundle install:

当我运行 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.

I have libpq-fe.h installed at /usr/pgsql-9.1/include/libpq-fe.h. So, I tried

我在 /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. 

Any help would be greatly appreciated.

任何帮助将不胜感激。

Also, I have installed postgresql91-devel and ruby-devel. Running CentOS 6.

另外,我已经安装了 postgresql91-devel 和 ruby​​-devel。运行 CentOS 6。

回答by Johannes Fahrenkrug

Have you tried running this before running bundle install?

你有没有试过在运行之前运行这个bundle install

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

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

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

回答by Lester Celestial

In case somebody used macports to install postgres and are having problems finding their pg_config, try this:

如果有人使用 macports 安装 postgres 并且在找到他们的 pg_config 时遇到问题,请尝试以下操作:

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

I hope this helps somebody save some time. Cheers!

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

回答by Jai Kumar Rajput

If you are not sure where your pg_config is, and assuming you are on Linux or Mac, you can run the following command:

如果您不确定 pg_config 在哪里,并且假设您使用的是 Linux 或 Mac,则可以运行以下命令:

which pg_config

this will return ==> /usr/pgsql-9.1/bin/pg_config

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

now use this path as

现在将此路径用作

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

Done now bundle install

现在完成 bundle install

回答by TTT

Had the same problem, fixed by installing libpq-dev.

有同样的问题,通过安装 libpq-dev 修复。

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

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

回答by Inanc Gumus

Copy & Paste:

复制粘贴:

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


Details:

细节:

Visit for more information:

The first thing you should do is ensure that the 'pg_config' tool that comes with Postgres is in your path. If it isn't, or the one that's first in your path isn't the one that was installed with the Postgres you want to build against, you can specify the path to it with the –with-pg-config option.

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

访问了解更多信息:

您应该做的第一件事是确保 Postgres 附带的“pg_config”工具在您的路径中。如果不是,或者您路径中的第一个不是与您要构建的 Postgres 一起安装的那个,您可以使用 –with-pg-config 选项指定它的路径。

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

回答by AndyM

You can get this error if you have pg_config installed but its not in any path. You can add it to your PATH env in your ~/.bashrc.

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

For example.

例如。

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

回答by superluminary

The Postgres gem can't find the Postgres configuration file. You need to tell it where it is. The most enjoyable solution to this in my opinion is to skip Brew and MacPorts and just use the Postgres app. Download and install from here:

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

http://postgresapp.com/

http://postgresapp.com/

Now add the bin folder to your path:

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

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

You may also wish to add this to your ~/.bash_profile

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

Now install the gem:

现在安装 gem:

gem install pg

it should go smoothly.

它应该顺利进行。

回答by Billy Kovalsky

I'm on Mac and i use Homebrew, so to fix this issue i just installed postgresql with brew:

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

brew install postgresql

And then installed the gem.

然后安装gem。

回答by Luke Sheppard

I had to do this to fix mine on OS X:

我必须这样做才能在 OS X 上修复我的:

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

And I had to do it despite the fact that I already had this in my 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

I hope that helps another Mac user with this problem.

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

回答by Joshua Michael Waggoner

I am using Arch Linux, and was having similar problems. Used sudo pacman -S libpqxxand reran then installed the pg gem and then ran bundle installagain, and this time it finally worked!

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