如何在 Ubuntu 上安装 PostgreSQL 的 pg gem?

发布于 2024-09-07 08:18:11 字数 1761 浏览 4 评论 0原文

我正在尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

我最亲爱的 2024-09-14 08:18:13

另一种选择是使用可在 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.)

驱逐舰岛风号 2024-09-14 08:18:12

需要添加包

sudo apt-get install libpq-dev

来在RoR中安装pg gem

Need to add package

sudo apt-get install libpq-dev

to install pg gem in RoR

仙女山的月亮 2024-09-14 08:18:12

ubuntu 用户的简单解决方案...

首先卸载所有 postgres 软件包,然后运行这些命令...

sudo apt-get install postgresql
sudo apt-get install postgresql-client libpq5 libpq-dev

# for rvm (single user)
mv ~/.rvm/usr/lib ~/.rvm/usr/lib_rvm 

# for rvm (multi-user)
mv /usr/local/rvm/usr/lib /usr/local/rvm/usr/lib_rvm

gem install pg  --   --with-pg-lib=/usr/lib

然后运行“bundle install”。一切都会好起来的。祝你有美好的一天!

Simple solution for ubuntu users...

First uninstall all postgres packages, then run these commads...

sudo apt-get install postgresql
sudo apt-get install postgresql-client libpq5 libpq-dev

# for rvm (single user)
mv ~/.rvm/usr/lib ~/.rvm/usr/lib_rvm 

# for rvm (multi-user)
mv /usr/local/rvm/usr/lib /usr/local/rvm/usr/lib_rvm

gem install pg  --   --with-pg-lib=/usr/lib

Then run 'bundle install'. Every thing will be fine. Have a good day!

帅的被狗咬 2024-09-14 08:18:12

sudo apt-get install postgresql-client libpq5 libpq-dev 然后执行gem install pg

sudo apt-get install postgresql-client libpq5 libpq-dev then do gem install pg

可遇━不可求 2024-09-14 08:18:12

对于 .RVM 用户来说会更好:

rvmsudo gem install pg -- --with-pg-lib=/usr/lib 

它对我有用(在我看到 jdupont 版本之后)

For .RVM users it will be better:

rvmsudo gem install pg -- --with-pg-lib=/usr/lib 

it worked for me (after i saw jdupont version)

晨光如昨 2024-09-14 08:18:12

如果您安装了 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.*):

rvm reinstall 1.9.3 --with-openssl-dir=/usr

这最终解决了我在 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):

rvm reinstall 1.9.3 --with-openssl-dir=/usr

This finally solved the problem for me on Ubunto 12.04.

深者入戏 2024-09-14 08:18:12

尝试一下

sudo apt-get install postgresql postgresql-contrib libpq-dev

您应该首先安装 PG 数据库服务器来安装客户端。然后,您安装客户端。

请参阅此博文了解有关设置的信息首次使用 PostGresSQL 进行 Ruby on Rails 开发。

Try this

sudo apt-get install postgresql postgresql-contrib libpq-dev

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.

孤单情人 2024-09-14 08:18:12

在这里的每个建议都失败后,这解决了我在 Ubuntu 12.04 上的问题。

rvmsudo gem install pg -v '0.12.2' -- --with-pg-lib=/usr/include/postgresql

This solved the problem for me on Ubuntu 12.04 after every suggestion here had failed.

rvmsudo gem install pg -v '0.12.2' -- --with-pg-lib=/usr/include/postgresql
揽月 2024-09-14 08:18:12

我试图在新安装的 Ubuntu 16.04 中设置一个 Rails 项目。我在运行捆绑包时遇到了同样的问题。运行

sudo apt-get install aptitude

sudo apt-get install libpq-dev

为我解决了这个问题。

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

sudo apt-get install aptitude

followed by

sudo apt-get install libpq-dev

Solved it for me.

云醉月微眠 2024-09-14 08:18:12

对于在尝试此页面上的所有答案后仍然遇到问题的任何人,以下(最终)有效:

sudo apt-get install libgmp3-dev
gem install pg

这是执行此页面上提到的所有其他操作之后。

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:

sudo apt-get install libgmp3-dev
gem install pg

This was after doing everything else mentioned on this page.

postgresql 9.5.8
Ubuntu 16.10

笑红尘 2024-09-14 08:18:12

这个问题的另一个解决方案是使用 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.

凉城 2024-09-14 08:18:12

对于那些尝试安装 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.

病女 2024-09-14 08:18:12

我遇到了同样的问题,并尝试了很多不同的变体。经过一番尝试后,我能够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.

落花随流水 2024-09-14 08:18:12

apt-get install ruby​​-dev 为我工作。

apt-get install ruby-dev worked for me.

可是我不能没有你 2024-09-14 08:18:11

您需要安装带有 PostgreSQL 标头的 postgreSQL 开发包

sudo apt-get install libpq-dev

You need install the postgreSQL dev package with header of PostgreSQL

sudo apt-get install libpq-dev
伪装你 2024-09-14 08:18:11

经过两天的阅读和折腾,并尝试了在其他笔记中找到的许多东西,下面的一行是我在 Ubuntu Lucid 10.04 上与一些 Maverick 软件包和 RVM 混合的解决方案(ruby 1.9.2-p290,rvm 1.10.2 ruby​​gems) 1.8.15、rails 3.0.1、postgres 8.4.10) :

gem install pg  --   --with-pg-lib=/usr/lib   

结果:

Building native extensions.  This could take a while...  
Successfully installed pg-0.13.1  
1 gem installed  
Installing ri documentation for pg-0.13.1...  
Installing RDoc documentation for pg-0.13.1...  

{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) :

gem install pg  --   --with-pg-lib=/usr/lib   

the result:

Building native extensions.  This could take a while...  
Successfully installed pg-0.13.1  
1 gem installed  
Installing ri documentation for pg-0.13.1...  
Installing RDoc documentation for pg-0.13.1...  

{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

思慕 2024-09-14 08:18:11

在 Ubuntu 中这对我有用,我希望对你有帮助

sudo apt-get install libpq-dev

gem install pg  --   --with-pg-lib=/usr/lib 

In Ubuntu this works for me, I hope help you:

sudo apt-get install libpq-dev

and

gem install pg  --   --with-pg-lib=/usr/lib 
狠疯拽 2024-09-14 08:18:11

安装 libpq-dev 对我不起作用。我还需要安装 build-essential

sudo apt-get install libpq-dev build-essential

Installing libpq-dev did not work for me. I also needed to install build-essential

sudo apt-get install libpq-dev build-essential
无声无音无过去 2024-09-14 08:18:11

我在 Ubuntu 12.10 上运行这个命令:

apt-get install libpq-dev

帮助我 - 之后运行 gem install pg -v "0.14.1",现在一切都好了

I'm on Ubuntu 12.10 and running this command:

apt-get install libpq-dev

helped me - after that ran gem install pg -v "0.14.1", and all good now

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文