如何在 Ubuntu 上安装 PostgreSQL 的 pg gem?
我正在尝试为 Ruby 安装 PostgreSQL 的 pg gem。
我发出了以下命令:
gem install pg
我使用 RVM 安装了 Ruby 1.9.2。
上面的命令显示了以下错误。
错误是:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby extconf.rb
checking for pg_config... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby
--with-pg
--without-pg
--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}/lib
--enable-static-build
--disable-static-build
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0/ext/gem_make.out
我不知道错误是什么......
I'm trying to install PostgreSQL's pg gem for Ruby.
I issued the following command:
gem install pg
I installed Ruby 1.9.2 using RVM.
The above command shows me the following error.
The error is :
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby extconf.rb
checking for pg_config... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby
--with-pg
--without-pg
--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}/lib
--enable-static-build
--disable-static-build
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0/ext/gem_make.out
I don't know what is the error...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
另一种选择是使用可在 Linux 和 macOS 上运行的 Homebrew 来仅安装支持库:
brew install libpq< /code>
然后
brew link libpq --force
(
--force
选项是必需的,因为它与 postgres 公式冲突。)Another option is to use Homebrew which works on Linux and macOS to install just the supporting libraries:
brew install libpq
then
brew link libpq --force
(the
--force
option is required because it conflicts with the postgres formula.)需要添加包
来在RoR中安装pg gem
Need to add package
to install pg gem in RoR
ubuntu 用户的简单解决方案...
首先卸载所有 postgres 软件包,然后运行这些命令...
然后运行“bundle install”。一切都会好起来的。祝你有美好的一天!
Simple solution for ubuntu users...
First uninstall all postgres packages, then run these commads...
Then run 'bundle install'. Every thing will be fine. Have a good day!
sudo apt-get install postgresql-client libpq5 libpq-dev
然后执行gem install pg
sudo apt-get install postgresql-client libpq5 libpq-dev
then dogem install pg
对于 .RVM 用户来说会更好:
它对我有用(在我看到 jdupont 版本之后)
For .RVM users it will be better:
it worked for me (after i saw jdupont version)
如果您安装了 libpq-dev 并且仍然遇到此问题,则可能是由于 OpenSSL 的 libssl 和朋友的版本冲突 - /usr/lib 中的 Ubuntu 系统版本(libpq 是针对该版本构建的)和安装在 $ 中的第二个版本 RVM HOME/.rvm/usr/lib(如果是系统安装,则为 /usr/local/rvm/usr/lib)。您可以通过临时重命名 $HOME/.rvm/usr/lib 并查看“gem install pg”是否有效来验证这一点。
要解决该问题,请使用系统 OpenSSL 库进行 rvm 重建(您可能需要从 rvm/usr/lib 目录中手动删除 libssl.* 和 libcrypto.*):
这最终解决了我在 Ubunto 12.04 上的问题。
If you have libpq-dev installed and are still having this problem it is likely due to conflicting versions of OpenSSL's libssl and friends - the Ubuntu system version in /usr/lib (which libpq is built against) and a second version RVM installed in $HOME/.rvm/usr/lib (or /usr/local/rvm/usr/lib if it's a system install). You can verify this by temporarily renaming $HOME/.rvm/usr/lib and seeing if "gem install pg" works.
To solve the problem have rvm rebuild using the system OpenSSL libraries (you may need to manually remove libssl.* and libcrypto.* from the rvm/usr/lib dir):
This finally solved the problem for me on Ubunto 12.04.
尝试一下
您应该首先安装 PG 数据库服务器来安装客户端。然后,您安装客户端。
请参阅此博文了解有关设置的信息首次使用 PostGresSQL 进行 Ruby on Rails 开发。
Try this
You should install PG Database server in the first place to install clients. Afterwards, you install clients.
See this blog post to know about setting up PostGresSQL for the first time for Ruby on Rails development.
在这里的每个建议都失败后,这解决了我在 Ubuntu 12.04 上的问题。
This solved the problem for me on Ubuntu 12.04 after every suggestion here had failed.
我试图在新安装的 Ubuntu 16.04 中设置一个 Rails 项目。我在运行捆绑包时遇到了同样的问题。运行
后
为我解决了这个问题。
I was trying to setup a Rails project in my freshly installed Ubuntu 16.04. I ran into the same issue while running bundle. Running
followed by
Solved it for me.
对于在尝试此页面上的所有答案后仍然遇到问题的任何人,以下(最终)有效:
这是在执行此页面上提到的所有其他操作之后。
postgresql 9.5.8
乌班图16.10
For anyone who is still having issues after trying all the answers on this page, the following (finally) worked:
This was after doing everything else mentioned on this page.
postgresql 9.5.8
Ubuntu 16.10
这个问题的另一个解决方案是使用 Homebrew/linuxbrew 安装 PostgreSQL:
brew install postgresql
作为一个习惯问题,我不喜欢使用 sudo,除非必须这样做。
Another solution to this problem is to install PostgreSQL using Homebrew/linuxbrew:
brew install postgresql
As a matter of habit I don't like to use sudo unless I have to.
对于那些尝试安装 Redmine 的人来说,在尝试了上述所有操作后,我错过了 sudo apt-get install ruby-all-dev 。
初始错误是
mkmf.rb 在 /usr/lib/ruby/include/ruby.h 处找不到 ruby 的头文件
。For those trying to install Redmine, I missed
sudo apt-get install ruby-all-dev
after trying all of the above.Initial error being
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
.我遇到了同样的问题,并尝试了很多不同的变体。经过一番尝试后,我能够
sudo gem install
,但在没有 sudo 的情况下安装它仍然存在问题。最后我找到了一个决定 - 重新安装rvm对我有帮助。也许它可以节省其他人的时间。
I had the same problem, and tried a lot of different variants. After some tries I became able to
sudo gem install
, but still have problem to install it without sudo.Finally I found a decission - reinstalling of rvm helped me. Probably it can save time somebody else.
apt-get install ruby-dev 为我工作。
apt-get install ruby-dev
worked for me.您需要安装带有 PostgreSQL 标头的 postgreSQL 开发包
You need install the postgreSQL dev package with header of PostgreSQL
经过两天的阅读和折腾,并尝试了在其他笔记中找到的许多东西,下面的一行是我在 Ubuntu Lucid 10.04 上与一些 Maverick 软件包和 RVM 混合的解决方案(ruby 1.9.2-p290,rvm 1.10.2 rubygems) 1.8.15、rails 3.0.1、postgres 8.4.10) :
结果:
{yea - 终于成功}!
!请注意,运行 pg_config 的输出在我的 Ubuntu / Postresql 安装上的 LIBS 变量中缺少 -lpq 项!
以及为什么在某些地方从pq切换到pg——让新手感到困惑?
我仍然不明白的是 -- 和 --with(option
但无论如何我已经超出了我的深度
After reading and thrashing around for 2 days, and trying many things found in other notes the following single line was the cure for me on Ubuntu Lucid 10.04 mixed with some Maverick packages and RVM (ruby 1.9.2-p290, rvm 1.10.2 rubygems 1.8.15, rails 3.0.1, postgres 8.4.10) :
the result:
{yea - finally success} !!
!note that the output from running pg_config lacks the item -lpq in the LIBS variable on my Ubuntu / Postresql install!!
and why the switch from pq to pg in certain places -- confusing to newbie ??
the thing I still do not understand is the double set of -- and --with(option
but I'm way beyond my depth anyway
在 Ubuntu 中这对我有用,我希望对你有帮助
:
In Ubuntu this works for me, I hope help you:
and
安装 libpq-dev 对我不起作用。我还需要安装 build-essential
Installing libpq-dev did not work for me. I also needed to install build-essential
我在 Ubuntu 12.10 上运行这个命令:
帮助我 - 之后运行 gem install pg -v "0.14.1",现在一切都好了
I'm on Ubuntu 12.10 and running this command:
helped me - after that ran gem install pg -v "0.14.1", and all good now