我尝试使用宝石安装pg,但它似乎不工作。

Gem install pg给出这个错误

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

C:/Ruby/bin/ruby.exe 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=C:/Ruby/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 C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1 for
inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1/ext/gem_make.out

当前回答

如果你使用asdf来安装postgres,只需要像这样安装pg gem:

asdf global postgres <version>
gem install pg

其他回答

我在Linux Mint (Maya) 13上解决了这个问题,我通过安装postgresql和postgresql-server来修复它:

apt-get install postgresql-9.1 

sudo apt-get install postgresql-server-dev-9.1

如果你使用asdf来安装postgres,只需要像这样安装pg gem:

asdf global postgres <version>
gem install pg
$ PATH=$PATH:/Library/PostgreSQL/9.1/bin sudo gem install pg

将9.1版本替换为系统上安装的版本。

回答: 不能在Windows上安装pg gem

的Windows原生版本 pg的最新版本(0.10.0)已经发布 昨天,但如果你安装了0.9.0它 是否应该安装二进制文件 问题。

你只要到这里看看你的pg版本是否支持Win32平台,然后使用这个命令来安装:

Gem install pg -v 0.14.1——platform=x86-mingw32