无法安装pg gem

Roh*_*hit 209 ruby installation rubygems ruby-on-rails

我尝试使用,gem install 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
Run Code Online (Sandbox Code Playgroud)

Dev*_*oop 378

我有这个问题,这对我有用:

安装postgresql-devel包,这将解决pg_config缺失的问题.

sudo apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)

  • 通过`apt-get install libpq-dev`为我工作.谢谢你的提示. (139认同)
  • @Fivell这里有答案,但是如果安装了Homebrew,那么`brew install postgresql`将为您提供所需的软件包. (22认同)
  • @Fivell在mac上尝试`brew install postgresql` (17认同)
  • 那mac怎么样? (16认同)
  • 确认,来自[pg gem Wiki主页](https://bitbucket.org/ged/ruby-pg/wiki/Home):"在Ubuntu上,/ usr/bin/pg_config由libpq-dev软件包提供." (5认同)

Mah*_*tam 84

问题是gem依赖所以在安装pg之前确保你已经安装了"libpq-dev"

Ubuntu系统:

sudo apt-get install libpq-dev

RHEL系统:

yum install postgresql-devel

苹果电脑:

brew安装postgresql

  • Mac的答案是真的.这只是因为我们没有在机器上安装PostgreSQL. (6认同)

Fla*_*viu 58

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

  • 在OS X上为我工作,但是带有/Applications/Postgres.app/Contents/MacOS/bin/pg_config的路径(我有一个独立的Postgres.app) (13认同)
  • 使用Postgres App在yosemite上使用`gem install pg - --with-pg-config =/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config` (10认同)
  • 这对我有帮助(在Centos 6.2上) (3认同)
  • 我为 OSX 10.12 使用了 `gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config` (2认同)

cre*_*gox 35

@Winfield :

pg gem需要postgresql客户端进行绑定.此错误通常意味着它无法找到您的Postgres库.要么您没有安装它们,要么您可能需要将它传递--with-pg-dir=给您的gem安装.

更重要的是,您只需要--with-pg-config=安装它.

在Mac上

如果,你有任何机会,你也通过mac上的网站捆绑安装了postgres,它将会在某个地方/Applications/Postgres.app/Contents/Versions/9.3/bin.

所以,要么你在gem安装上传递它:

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Run Code Online (Sandbox Code Playgroud)

或者正确设置PATH.由于这可能太多,暂时设置PATH:

export PATH=%PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/
Run Code Online (Sandbox Code Playgroud)

  • 具体版本:`gem install pg -v'0.17.1' - --with-pg-config =/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config` (2认同)

Las*_*ert 24

我没有安装postgresql,所以我只是用它来安装它

sudo apt-get install postgresql postgresql-server-dev-9.1
Run Code Online (Sandbox Code Playgroud)

在Ubuntu 12.04上.

这解决了它.


更新:

使用最新版本:

sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3
Run Code Online (Sandbox Code Playgroud)


小智 16

在我的情况下工作,我使用ubuntu 14.04.2 LTS

sudo apt-get install libpq-dev

我用

Ruby 2.2.2和Rails 4.2.1


Nik*_*kov 14

这里回答: 无法在Windows上安装pg gem

昨天发布的最新版本的pg(0.10.0)没有Windows原生版本,但如果安装0.9.0,它应该安装二进制文件而不会出现问题.


Dar*_*rme 11

如果您在Mac 上使用Postgres.app,您可以一劳永逸地解决此问题,如下所示:

首先gem uninstall pg,然后编辑~/.bash_profile~/.zshrc文件或同等学历,并添加:

# PostgreSQL bin path
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
Run Code Online (Sandbox Code Playgroud)

然后bundle install,gem install pg两者都应该按预期工作.


jst*_*nno 9

$ PATH=$PATH:/Library/PostgreSQL/9.1/bin sudo gem install pg
Run Code Online (Sandbox Code Playgroud)

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


小智 5

在Mac OS(El Capitano)上.你可以简单地使用:brew install postgresql