找不到'libpq

我正在使用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

我该如何解决这个问题?


它看起来像在Ubuntu中,头文件是libpq-dev软件包的一部分(至少在以下Ubuntu版本中为:11.04(Natty Narwhal),10.04(Lucid Lynx),11.10(Oneiric Ocelot),12.04(精确穿山甲)和14.04 Trusty Tahr)):

...
/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

  • macOS (以前的Mac OS XOS X )上,使用Homebrew安装正确的标题:

    brew install postgresql
    

    然后运行

    gem install pg
    

    应该管用。


    我也试过做gem install 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
    

    没有问题。

    链接地址: http://www.djcxy.com/p/81105.html

    上一篇: Can't find the 'libpq

    下一篇: customize gem from github