Ruby-on-rails Rails 3 - 无法安装 pg gem

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9668753/
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-03 03:01:50  来源:igfitidea点击:

Rails 3 - can't install pg gem

ruby-on-railsmacospostgresql-9.1pglibpq

提问by user984621

When I try to run bundle (bundle install), I all the time get

当我尝试运行捆绑包(捆绑安装)时,我总是得到

Installing pg (0.13.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/ryan/.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
    --without-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=/Users/ryan/.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 /Users/ryan/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2 for inspection.
Results logged to /Users/ryan/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2/ext/gem_make.out
An error occured while installing pg (0.13.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.13.2'` succeeds before bundling.

I use Mac OS X 10.6, the version of installed PostgreSQL is 9.1. I found the problem is in the libpq-dev, how could I install/fix that?

我使用 Mac OS X 10.6,安装的 PostgreSQL 版本是 9.1。我发现问题出在libpq-dev 中,我该如何安装/修复它?

采纳答案by Ethan

As stated in your error log you need to pass in the path to the pg_config. Try to install the gem using:

正如您的错误日志中所述,您需要将路径传递给 pg_config。尝试使用以下方法安装 gem:

gem install pg -- --with-pg-config= 'PATH_TO_YOUR_PG_CONFIG'

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

Your pg-config can be in different locations depending on how you installed postgres.

根据您安装 postgres 的方式,您的 pg-config 可以位于不同的位置。

回答by E.E.33

if you are running on Linux you may be interested in what worked for me:

如果您在 Linux 上运行,您可能会对对我有用的内容感兴趣:

sudo apt-get install postgresql
sudo apt-get install libpq-dev

Then

然后

gem install pg

then

然后

bundle install

src: http://wikimatze.de/installing-postgresql-gem-under-ubuntu-and-mac

源代码:http: //wikimatze.de/installing-postgresql-gem-under-ubuntu-and-mac

回答by Ari

If you're using Postgress.appthen youll want access to its command-line tools. Enter the following line in your terminal or your PATH profile:

如果您使用Postgress.app,那么您将需要访问其命令行工具。在终端或PATH 配置文件中输入以下行:

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

gem install pgshould now work. (This is what worked for me.)

gem install pg现在应该可以工作了。(这对我有用。)

NoteNew versions path looks like:

注意新版本路径如下所示:

/Applications/Postgres.app/Contents/Versions/<version>/bin

回答by user2373148

If you have homebrew, just type:

如果你有自制软件,只需输入:

$ brew install postgresql

$ brew 安装 postgresql

If you dont have it, download typing this in your terminal:

如果没有,请在终端中输入以下内容下载:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

回答by jlucasps

Search for libpq:

搜索 libpq:

brew search libpq

Should output libpqxx

应该输出 libpqxx

Then try install it:

然后尝试安装它:

brew install libpqxx

回答by Travis Reeder

You only need to install libpq-dev:

您只需要安装libpq-dev

sudo apt-get install libpq-dev

Then the gem should install just fine.

然后 gem 应该安装得很好。

回答by CGK

Follow the post-installation instructions: http://postgresapp.com/documentation/configuration-ruby.html

按照安装后说明进行操作:http: //postgresapp.com/documentation/configuration-ruby.html

To install the pg gem, make sure you have set up your $PATH correctly (as specified in http://postgresapp.com/documentation/cli-tools.html), then run

要安装 pg gem,请确保您已正确设置 $PATH(如http://postgresapp.com/documentation/cli-tools.html 中所述),然后运行

sudo ARCHFLAGS="-arch x86_64" gem install pg

sudo ARCHFLAGS="-arch x86_64" gem install pg

I stronglyrecommend reading both pages. Just skimmed them and lost 1 hour of my life. Read them, problem solved.

强烈建议阅读这两页。只是略读它们,就失去了我生命中的 1 小时。阅读它们,问题解决了。

回答by Trang Tung Nguyen

I got the same issue but my Postgres was install in

我遇到了同样的问题,但我的 Postgres 安装在

/Library/PostgreSQL/9.3

/Library/PostgreSQL/9.3

Updated the ~/.bash_profile by adding:

通过添加更新 ~/.bash_profile :

export PATH=/Library/PostgreSQL/9.3/bin:$PATH

Open a new terminal, run bundle updateand also it worked for me. Thanks Ari.

打开一个新终端,运行bundle update它也对我有用。谢谢阿里。

回答by dfrankow

The problem I had was that for some reason it was trying to compile with /usr/bin/gcc-4.2. I found that out by changing try_cpp in mkmf.rb (which I saw in the stack trace) to raise an exception with the compile line that was failing.

我遇到的问题是由于某种原因它试图用 /usr/bin/gcc-4.2 编译。我通过更改 mkmf.rb(我在堆栈跟踪中看到的)中的 try_cpp 来引发一个异常,编译行失败了。

I soft-linked gcc to gcc-4.2 and it worked:

我将 gcc 软链接到 gcc-4.2 并且它起作用了:

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

Why was it trying to use gcc-4.2? No idea.

为什么要尝试使用 gcc-4.2?不知道。

The actual compile line:

实际编译行:

/usr/bin/gcc-4.2 -E -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/backward -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/local/Cellar/postgresql/9.1.4/include  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration  -fno-common -pipe  conftest.c -o conftest.i (RuntimeError)

回答by Konstantin Kalbazov

You can set a build config option bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_configand use gem install pgwithout any options (the path to pg_config may be different for you, this one is for the Postgresapp 9.3.5.0)

您可以设置一个构建配置选项bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config并在gem install pg没有任何选项的情况下使用(pg_config 的路径对您来说可能不同,这个是用于 Postgresapp 9.3.5.0)