Rails 3 - 无法安装pg gem

100
每当我尝试运行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.

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


2
你在 Mac 上如何安装 Postgres? - shingara
1
方式 - user984621
点击安装程序?Flink?还是MacPort? - shingara
我尝试通过这种方式安装:sudo port install libpq-dev,但又出现了另一个问题 - Error: Port libpq-dev not found。要报告错误,请参见<http://guide.macports.org/#project.tickets>。这太糟糕了,还有一些问题... - user984621
1
请查看这个问题:这里 - banditKing
16个回答

1
你可以设置一个构建配置选项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的)。

0
在 Fedora 上:
dnf install postgresql-devel

0

0

你可以通过进入lib文件夹,然后输入cd ~/opt/local/lib/并最后输入ls命令来检查终端中是否有一个postgresql文件。这将显示位于lib目录下的所有文件列表。

1.如果没有postreseql,则可以通过macports进行下载。 sudo port install postgresql93 @ 9.3.2_1

现在,切换回您要安装的文件夹

  1. 使您的pg可以与您已经拥有或刚刚下载的Postgesql文件一起使用 gem install pg -- --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config

现在运行 bundle install


0

在El Capitan上,对我有用的是将ruby从系统默认版本升级到2.3.1,这似乎找到了pg gem所需的正确库。


0

首先,卸载任何Homebrew版本。--force选项会卸载所有版本。

brew rm postgresql --force

根据您的版本相应地更改路径。

sudo /sbin/SystemStarter stop postgresql-8.4
sudo rm -rf /Applications/PostgreSQL\ 8.4
sudo rm -rf /etc/postgres-reg.ini
sudo rm -rf /Library/StartupItems/postgresql-8.4
sudo rm -rf /Library/PostgreSQL/8.4
sudo dscl . delete /users/postgres

编辑 /etc/profile 并删除任何引用 "postgres" 的行。

nano /etc/profile

安装PostgreSQL
brew update
brew install postgresql

安装 PG GEM

gem install pg

就这些。谢谢。


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