我使用的是Ruby on Rails 3.1预版本。我喜欢使用PostgreSQL,但问题是安装pg gem。它给了我以下错误:

$ gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /home/u/.rvm/rubies/ruby-1.9.2-p0/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=/home/u/.rvm/rubies/ruby-1.9.2-p0/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 /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0 for inspection.
    Results logged to /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0/ext/gem_make.out

我怎么解决这个问题?


当前回答

我也遇到过类似的问题,这个方法帮我解决了问题:

gem install do_postgres -- --with-pgsql-server-dir=/Applications/Postgres.app/Contents/MacOS --with-pgsql-server-include=/Applications/Postgres.app/Contents/MacOS/include/server

来源:

https://gist.github.com/oisin/6562181

其他回答

在Ubuntu 20.04上,我已经有libpq5:amd64 version 13.2-1.pgdg20.04+1。现在,当我试图从apt存储库安装libpq-dev时,我正在接收

The following packages have unmet dependencies:
libpq-dev : Depends: libpq5 (= 12.6-0ubuntu0.20.04.1) but 13.2-1.pgdg20.04+1 is to be installed

我从http://ftp.us.debian.org/debian/pool/main/p/postgresql-13/libpq-dev_13.2-1_amd64.deb上获取了deb,并做了以下工作:

mkdir -p /tmp/libpq-dev
dpkg-deb -R libpq-dev_13.2-1_amd64.deb /tmp/libpq-dev
sed -i 's|= 13.2-1|= 13.2-1.pgdg20.04+1|' /tmp/libpq-dev/DEBIAN/control
dpkg-deb -b /tmp/libpq-dev /tmp/libpq-dev-new.deb
sudo dpkg -i /tmp/libpq-dev-new.deb

从那以后,我一直在愉快地使用宝石。没有额外的安装或任何东西。

我最终解决了这个问题,但没有使用前面描述的方法。

使用brew install postgresql,我发现它已经安装了,但没有链接。

找出PostgreSQL安装的位置,并删除它, 然后再次安装postgresql, 酿造链接postgresql Gem install pg

我也尝试过做gem安装libpq-dev,但我收到了这个错误:

Can't find the 'libpq-fe.h header
*** extconf.rb failed ***

然而,我发现使用sudo apt-get(我尽量避免在Ruby on Rails中使用)安装是有效的,即。

sudo apt-get install libpq-dev
# or
apt-get install postgres-server-dev-{pg.version}
# for postgresql 9.4 on Ubuntu 14.04

然后我就能做了

gem install pg

没有问题。

我最近升级到Mac OS X v10.10 (Yosemite),在构建pg gem时遇到了困难。

报告的错误是典型的:

Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***

我的解决方案是卸载pg gem,然后捆绑更新pg,用最新的gem替换gem。我确实运行了brew update;在Yosemite安装后进行brew升级,以获得我之前安装的软件包的最新版本。

在我的情况下,它是包postgresql-server-dev-8.4(我使用的是Ubuntu 11.04 (Natty Narwhal), 64位)。