Rails 3 - 无法安装pg gem

use*_*621 96 macos ruby-on-rails libpq pg postgresql-9.1

当我尝试运行bundle(bundle install)时,我总是得到

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.
Run Code Online (Sandbox Code Playgroud)

我使用的是Mac OS X 10.6,安装的PostgreSQL的版本是9.1.我发现问题出在libpq-dev中,我怎么能安装/修复它?

E.E*_*.33 99

如果你在Linux上运行,你可能会对我有用的东西感兴趣:

sudo apt-get install postgresql
sudo apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)

然后

gem install pg
Run Code Online (Sandbox Code Playgroud)

然后

bundle install
Run Code Online (Sandbox Code Playgroud)

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

  • 不适合OS X. (21认同)

Eth*_*han 78

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

gem install pg -- --with-pg-config= 'PATH_TO_YOUR_PG_CONFIG'
Run Code Online (Sandbox Code Playgroud)

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

which pg_config
Run Code Online (Sandbox Code Playgroud)

您的pg-config可以位于不同的位置,具体取决于您安装postgres的方式.

  • 在OSX上你也可以使用brew通过`brew install libpqxx`来获取标题,一切都会好起来的. (13认同)
  • `哪个pg_config`比`find/-name pg_config`快? (8认同)
  • 这里的二进制包:http://www.enterprisedb.com/products-services-training/pgdownload#osx肯定*确实*包含`pg_config`(例如,在`/Library/PostgreSQL/9.1/bin/pg_config `for 9.1.x)和开发标题.这是我用来测试开发中的`pg`宝石. (3认同)

Ari*_*Ari 56

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

 PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

gem install pg现在应该工作.(这对我有用.)

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

/Applications/Postgres.app/Contents/Versions/<version>/bin
Run Code Online (Sandbox Code Playgroud)

  • 请注意,93版本中的Postgre.app补丁已更改.它现在是:/Applications/Postgres93.app/Contents/MacOS/bin (7认同)
  • 现在这是 - /Applications/Postgres.app/Contents/Versions/9.3/bin`,如果您使用Postgres.app,则为9.3.5 (5认同)
  • 非常感谢!我花了半个小时去处理那些不起作用的东西,最后发现这里被埋没了.:d (3认同)
  • 这对我有用,虽然我的垃圾箱位于一个非常不同的地方 - > /Library/PostgreSQL/9.3/bin (2认同)

小智 21

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

$ brew install postgresql

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

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


小智 12

搜索libpq:

brew search libpq
Run Code Online (Sandbox Code Playgroud)

应输出 libpqxx

然后尝试安装它:

brew install libpqxx
Run Code Online (Sandbox Code Playgroud)


Tra*_*der 7

您只需要安装libpq-dev:

sudo apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)

然后宝石应该安装得很好.

  • 不适合OS X. (8认同)

CGK*_*CGK 7

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

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

sudo ARCHFLAGS="-arch x86_64" gem install pg

强烈建议您阅读这两页.只是撇去它们,失去了我生命中的一小时.读它们,问题解决了.