我现在用的是Ruby on Rails的3.1版本前。我喜欢使用PostgreSQL,但问题是安装pg
宝石。它给了我下面的错误:
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/u/.rvm/rubies/ruby-1.9.2-p0/bin/ruby 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=/home/u/.rvm/rubies/ruby-1.9.2-p0/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 /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0 for inspection.
Results logged to /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0/ext/gem_make.out
我该如何解决这个问题?
它看起来像在Ubuntu该标题是libpq-dev
package(至少在下面的Ubuntu版本的一部分:11.04(纳蒂独角鲸),10.04(清醒山猫),11.10(解梦山猫),12.04(精确穿山甲),14.04(可信赖的塔尔羊)和18.04(仿生海狸)):
...
/usr/include/postgresql/libpq-fe.h
...
因此,尝试安装libpq-dev
或等值您的操作系统:
sudo apt-get install libpq-dev
yum install postgresql-devel
brew install postgresql
gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
zypper in postgresql-devel
为Mac用户提供Postgres.app正确的答案是建立针对具备包postgresql-server-dev-8.4
。例如,与9.4版本(目前为写这篇文章的),你需要的是:
Ubuntu 11.04
这将让你的libpq
宝石同步与正是你所安装的PostgreSQL的版本。从安装自制的东西是在这种情况下浪费。
我对亚马逊的Linux同样的问题。我能找到的头export CONFIGURE_ARGS="with-pg-include=/Applications/Postgres.app/Contents/Versions/9.4/include"
gem install pg
,但不知何故,没有工作。
它来自不同版本通过机器上的不同用户已安装的软件包。 PostgreSQL的9.2和PostgreSQL 9.3安装了。因此,请确保您的PostgreSQL版本,包括库之前。
对我来说,神奇的命令行是:
pg
来源:libpq-fe.h
对于任何基于Debian的分布的更一般的回答(它包括Ubuntu的)如下。首先,安装sudo yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel
包以root身份运行:
An almost idiot's guide to install PostgreSQL 9.3, PostGIS 2.1 and pgRouting with Yum
这使您可以搜索包含一个文件包。然后,使用更新其数据库
apt-file
(这可以作为普通用户运行)。然后,查找使用缺少的头:
apt-get install apt-file
在我的机器,这给:
apt-file update
你去那里!
我在Mac上运行Postgres.app,我不得不
apt-file search libpq-fe.h
第一。然后
libpq-dev: /usr/include/postgresql/libpq-fe.h
postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h
为我工作。
我在Mac OS同样的问题,但我很容易地通过使用在终端下面安装PostgreSQL的宝石:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
(我安装的PostgreSQL首先用bundle install
。)
我发现这个答案,这是只为我工作(Mac OS)中的一个 - 研究约两天后:
ARCHFLAGS="-arch x86_64" gem install pg
见堆栈溢出问题brew install postgresql
。
我最近升级到$ sudo su
$ env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions. This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...
(优胜美地)和有困难建立Can't find the PostgreSQL client library (libpq)宝石。
报告的错误是典型的:
Mac OS X v10.10
我的解决办法是pg
然后Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***
使用最新的替换宝石。我没跑gem uninstall pg
后,优胜美地安装以获得我以前安装的软件包的最新版本。
在Mac上,我解决了它使用此代码:
bundle update pg
对于没有安装PostgreSQL服务器的MacOS:
brew update; brew upgrade
在CentOS,我安装gem install pg -v '0.18.4' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
使用下面的命令
brew install libpq
gem install pg -- --with-pg-config="/usr/local/Cellar/libpq/9.6.6/bin/pg_config"
执行libpq-dev package
返回相同的错误“yum install postgresql-devel
”。
安装宝石如下解决我的问题
gem install pg
在Ubuntu上,安装“的libpq-dev的”摆脱这个问题。
No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config
在FreeBSD(9.1)所需的包装是/ usr /端口/数据库/里面装也将安装所需的头文件,使创业板安装的“PG”当的PostgreSQL服务器*失败。这里这个答案帮我找到了解决办法,但在包名的不同需要进行一些搜索的。
希望这可以帮助别人避免了一下头了在FreeBSD系统上的“-dev”搜索包时刮伤!
在gem install pg -- --with-pg-config=/usr/pgsql-x.x/bin/pg_config
7.0,64位(喘息),只需要运行:
sudo apt-get install libpq-dev
你成功安装的libpq-dev的后,运行:
Debian
在CentOS的6.5(挤压),我创建了一个文件:
sudo apt-get install libpq-dev
与内容:
bundle install
注意这里,你应该用pg_config文件中设置你的PostgreSQL路径。你可以用命令来查找这样的:
$ sudo touch /etc/profile.d/psql.sh
保存文件:
pathmunge /usr/pgsql-9.3/bin
并再次尝试执行你的命令。
注意:每次更改$ sudo find / -iname pg_config
配置 - 改变的profile.d配置 - 你应该重新加载猛砸。
$ sudo chmod +x /etc/profile.d/ruby.sh
的位置取决于你的PostgreSQL安装在哪里(这取决于你如何安装)。使用Bash(libpq-fe.h
)找到你的机器上的文件locate
。如果它存在,它会在你的PostgreSQL安装的http://en.wikipedia.org/wiki/Locate_%28Unix%29目录。
libpq-fe.h
该include
目录,其中包含$ locate libpq-fe.h
/Library/PostgreSQL/9.1/include/libpq-fe.h
,将在同一目录中bin
目录。正如错误提示,使用--with-PG-config选项来安装宝石:
pg_config
请注意,您可能需要运行include
如果你从来没有使用$ gem install pg --with-pg-config="/Library/PostgreSQL/9.1/bin/pg_config"
或者如果你还没有,因为安装PostgreSQL更新。
我终于解决了这个问题,但没有使用前面描述的方法。
使用updatedb
,我发现它已经安装,但没有联系。
locate
再次,brew install postgresql
brew install postgresql
我只是有这个在OSX上运行的BREW和brew link postgresql
。
我的修复是这样的:
gem install pg
我曾在PostgreSQL 9.6这个问题。我能够做修复它:
[email protected]
对于CONFIGURE_ARGS="with-pg-include=/usr/local/opt/[email protected]/include/" bundle install
包brew upgrade [email protected]
brew link [email protected] --force
gem install pg
(在我的情况AltLinux
)必须安装:
postgresqlx.x-devel
我解决了这个安装“PostgreSQL的常见”包。该软件包提供了postgresql9.5-devel
二进制这是最有可能你错过了什么。
我也想这样做PATH
,但我收到此错误:
PKG_CONFIG_PATH
但是我发现,gem install libpq-dev
安装(我尽量避免与Ruby on Rails的使用)的工作,即
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
然后,我能够做
sudo apt-get
没有问题。
我有一个类似的问题,而这个固定对我来说:
apt-get install postgresql9.5-devel
资源:
pg_config
我会以另一种方式解决这个问题。我没有找到我的系统上的库。因此,我安装了它使用和PostgreSQL的主要网站的应用程序。在我的情况(OS X),我发现文件下sudo apt-get install libpq-dev
# or
apt-get install postgres-server-dev-{pg.version}
# for postgresql 9.4 on Ubuntu 14.04
一旦安装就结束了。您还可能有文件的其他地方取决于你的系统,如果您已经安装PostgreSQL的。
2009年,由于gem install pg
这个环节,我可以在宝石指向与此命令的lib:
/Library/PostgreSQL/9.1/include/
在此之后,它的作品,因为它现在知道在哪里可以找到失踪的库。只是你的libpq-fe.h正确的位置更换路径
找不到libpq的-fe.h头
我已经成功在CentOS 7.0.1406运行以下命令:
how to add an additional path for gem installation
另外,您也可以配置成束总是使用这些选项安装export CONFIGURE_ARGS="with-pg-include=/Library/PostgreSQL/9.1/include/"
gem install pg
(运行在部署环境中捆绑有帮助)
~ % psql --version # => psql (PostgreSQL) 9.4.1
yum install libpqxx-devel
gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config
对于pg
6.4,
bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config
效果很好!
在Mac OS X上运行是这样的:
yum install postgresql-devel
gem install pg
gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
是pg_config路径
在我的情况下,它是包gem install pg -- --with-pg-config=***/path/to/pg_config***
(我在***/path/to/pg_config***
(纳蒂独角鲸),64位)。