使用'gem pq'安装PostgreSQL gem失败,出现错误:无法构建本地扩展宝石。

35

我正在学习Ruby on Rails并尝试开发一个应用程序。 在我的应用程序中,我试图在开发模式下使用默认的SQLite数据库,而在生产模式下使用PostgreSQL。 但是,在尝试使用gem install pg安装pg gem时,我遇到了以下错误。

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.
 
    /home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev
 for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev
 for building a client-side application.
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/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
        --with-pg
        --without-pg
        --with-pg-config
        --without-pg-config
        --with-pg_config
        --without-pg_config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/
 
 
Gem files will remain installed in /home/tusharkhatiwada/.rvm/gems/ruby-2.0.0-p247@rails4.0.0/g
ems/pg-0.17.0 for inspection.
Results logged to /home/tusharkhatiwada/.rvm/gems/ruby-2.0.0-p247@rails4.0.0/gems/pg-0.17.0/ext
/gem_make.out

之后我再次尝试使用 gem install pg -- --with-pg-config= '/usr/bin/pg_config' 命令,但是出现了以下错误:

Building native extensions with: '--with-pg-config= /usr/bin/pg_config'
This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.
 
    /home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb --with-pg-config= /us
r/bin/pg_config
Using config values from 
sh: 1: : Permission denied
sh: 1: : Permission denied
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/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
        --with-pg
        --without-pg
        --with-pg-config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/
 
 
Gem files will remain installed in /home/tusharkhatiwada/.rvm/gems/ruby-2.0.0-p247@rails4.0.0/g
ems/pg-0.17.0 for inspection.
Results logged to /home/tusharkhatiwada/.rvm/gems/ruby-2.0.0-p247@rails4.0.0/gems/pg-0.17.0/ext
/gem_make.out

如何在Ubuntu上安装gem pg - techvineet
@techvineet:这也没有解决我的问题。 - Tushar Khatiwada
你的软件包管理器出现了一些问题。首先,通过sudo apt-get update更新你的软件包管理器,然后尝试安装这些软件包。 - techvineet
3个回答

125
如果您正在使用Ubuntu,请尝试安装以下lib文件。

如果您正在使用Ubuntu,请尝试安装以下lib文件。

sudo apt-get install libpq-dev

然后运行gem install pg

这对我起作用了。


我尝试了,但它也显示错误: 您可能需要运行“apt-get -f install”来纠正这些问题: 以下软件包存在未满足的依赖关系:  libpq-dev:依赖于libkrb5-dev,但不会安装              依赖于comerr-dev,但不会安装  libssl-dev:依赖于libssl1.0.0(= 1.0.1c-4ubuntu8.1),但将安装1.0.1c-4ubuntu8              建议安装libssl-doc,但不会安装 E:未满足的依赖关系。尝试使用无软件包的“apt-get -f install”(或指定解决方案)。 - Tushar Khatiwada
sudo apt-get update sudo apt-get install build-essential ruby-dev libpcap-dev - santosh
使用 Turnkey Linux 版本升级 GitLab 从 5.1 到 6.0 时,这个方法是有效的。 - Matt Slagle
每当我安装PostgreSQL时,我知道会出现错误,然后我会通过谷歌搜索复制粘贴这个命令来解决这个问题。 - Paritosh Piplewar
你是怎么意识到这个缺失的? - Jim
显示剩余4条评论

0

对于那些通过谷歌搜索到达这里的人 如果 libpq-dev 没有起作用 或者出现其他错误 我也遇到了同样的问题 尝试升级您的系统 并获取 Ruby Dev-Kit

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ruby1.9.1-dev

然后重新启动 之后再试一次

...


0

你必须这样做

sudo apt-get install libgmp-dev libpq-dev

然后

gem install pg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接