我尝试使用宝石安装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

当前回答

Gem install pg -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config

其他回答

多年来,我一直在PG身上遇到这个烦人的问题。我写了这个要点来帮助你。

下面的命令总是对我有用。

# Substitute Postgres.app/Contents/Versions/9.5 with appropriate version number
sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config

要点:https://gist.github.com/sharnie/5588340cf023fb177c8d

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

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

我在Linux (Pop_OS) 20.10上使用Ruby(和其他版本)的版本管理器(asdf),在尝试了100万种不同的方法对其进行排序后,包括上述所有内容

TLDR

gem install pg -v '1.2.3' -- --with-pg-config='/home/username/.asdf/installs/postgres/12.6/bin/pg_config'

找到正确版本的PG install,并指向bin目录中的pg_config

pg gem需要绑定postgresql客户端库。这个错误通常意味着它找不到你的Postgres库。要么你没有安装它们,要么你可能需要传递——with-pg-dir=到你的gem安装中。

在Mac上安装postgres然后捆绑安装