Ruby-on-rails 使用“gem pq”安装 PostgreSQL gem 失败并显示错误:无法构建 gem 本机扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18864112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:44:04  来源:igfitidea点击:

Installing the PostgreSQL gem with 'gem pq' fails with ERROR: Failed to build gem native extension

ruby-on-railsrubypostgresqlgempg

提问by Tushar Khatiwada

I am learning Ruby on Rails and trying to develop an application. In my application I am trying to use the default SQLite database in the Development Modeand PostgreSQL in the Production Mode. But I'm getting the following error while trying to install pg gem using: gem install pg

我正在学习 Ruby on Rails 并尝试开发一个应用程序。在我的应用我试图使用默认的开发模式SQLite数据库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/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/[email protected]/g
ems/pg-0.17.0?for?inspection.
Results?logged?to?/home/tusharkhatiwada/.rvm/gems/[email protected]/gems/pg-0.17.0/ext
/gem_make.out

After that I again tried with gem install pg -- --with-pg-config= '/usr/bin/pg_config'and the following error is displayed:

之后我再次尝试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/[email protected]/g
ems/pg-0.17.0?for?inspection.
Results?logged?to?/home/tusharkhatiwada/.rvm/gems/[email protected]/gems/pg-0.17.0/ext
/gem_make.out

回答by santosh

If you are using Ubuntu try to install following lib file

如果您使用的是 Ubuntu,请尝试安装以下 lib 文件

sudo apt-get install libpq-dev

and then gem install pg

然后 gem install pg

worked for me.

对我来说有效。

回答by Haytham Mtair

for those who reached this by google search if libpq-dev didnt work or threw another errors i hade the same problem try upgrading your system and get the ruby div-kit

对于那些通过谷歌搜索达到这个的人,如果 libpq-dev 没有工作或抛出另一个错误,我遇到了同样的问题,请尝试升级您的系统并获取 ruby​​ div-kit

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

then reboot after this just try again

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

...

...

回答by Paritosh Piplewar

You have to do this

你必须这样做

sudo apt-get install libgmp-dev libpq-dev

and then

进而

gem install pg