安装pg gem时找不到'libpq-fe.h头文件?

  • 回答 (2)
  • 关注 (0)
  • 查看 (794)

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

demonchand@system-001:~/exercise/personal/pro$ gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.
        /home/demonchand/.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 heade
*** 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-di
    --without-opt-di
    --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=.
    --curdi
    --ruby=/home/demonchand/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
    --with-pg
    --without-pg
    --with-pg-di
    --without-pg-di
    --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/demonchand/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0 for inspection.
Results logged to /home/demonchand/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0/ext/gem_make.out

我如何解决这个问题?

看破红尘的黑猫看破红尘的黑猫提问于
御姐万岁回答于

在Mac OS X上,使用Homebrew安装正确的标题:

brew install postgresql

然后运行

gem install pg
秋之夕颜清念念不忘,必有回响回答于

它看起来像在Ubuntu中,头是libpq-dev包的一部分(至少在下面的Ubuntu版本: 11.04,10.04,11.10,12.04和14.04):

...
/usr/include/postgresql/libpq-fe.h
...

因此,请尝试安装libpq-dev或其相当于您的操作系统:

  • 对于Ubuntu系统: sudo apt-get install libpq-dev
  • 在Red Hat Linux(RHEL)系统上:yum install postgresql-devel
  • 对于Mac Homebrew:brew install postgresql
  • 对于Mac MacPorts PostgreSQL:gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
  • 对于OpenSuse:zypper in postgresql-devel

扫码关注云+社区

领取腾讯云代金券