使用“gem pq”安装 PostgreSQL gem 失败并出现错误:无法构建 gem 本机扩展
Posted
技术标签:
【中文标题】使用“gem pq”安装 PostgreSQL gem 失败并出现错误:无法构建 gem 本机扩展【英文标题】:Installing the PostgreSQL gem with 'gem pq' fails with ERROR: Failed to build gem native extension 【发布时间】:2013-09-22 17:36:19 【问题描述】:我正在学习 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/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
【问题讨论】:
重复***.com/questions/3116015/… @techvineet :它也没有解决我的问题。 你的包管理器有问题。首先,通过 sudo apt-get update 更新你的包管理器,然后尝试安装这些。 【参考方案1】:你必须这样做
sudo apt-get install libgmp-dev libpq-dev
然后
gem install pg
【讨论】:
【参考方案2】:对于那些通过谷歌搜索到达这里的人 如果 libpq-dev 不起作用 或抛出另一个错误 我有同样的问题 尝试升级您的系统 并获得 ruby div-kit
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ruby1.9.1-dev
然后重启 之后再试一次
...
【讨论】:
【参考方案3】:如果您使用的是 Ubuntu,请尝试安装以下 lib 文件
sudo apt-get install libpq-dev
然后 gem install pg
为我工作。
【讨论】:
我试过了,但它也显示错误:You might want to run 'apt-get -f install' to correct these: The following packages have unmet dependencies: libpq-dev : Depends: libkrb5-dev but it is not going to be installed Depends: comerr-dev but it is not going to be installed libssl-dev : Depends: libssl1.0.0 (= 1.0.1c-4ubuntu8.1) but 1.0.1c-4ubuntu8 is to be installed Recommends: libssl-doc but it is not going to be installed E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
sudo apt-get update sudo apt-get install build-essential ruby-dev libpcap-dev
这个解决方案在我安装在云服务器Koding 的虚拟机上不起作用,但它确实在我使用 Ubuntu 的笔记本电脑上解决了。
这在使用交钥匙 linux 版本将 gitlab 从 5.1 升级到 6.0 时有效。
每当我安装 postgresql 时,我都知道会发生错误,我将复制粘贴此命令以通过 google-ing 解决此问题。以上是关于使用“gem pq”安装 PostgreSQL gem 失败并出现错误:无法构建 gem 本机扩展的主要内容,如果未能解决你的问题,请参考以下文章
[postgreSQL] Use the escape string syntax for escapes, e.g., E' '.