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

pal*_*ani 280 ruby postgresql pg

我正在尝试为Ruby安装PostgreSQL的pg gem.

我发出了以下命令:

gem install pg
Run Code Online (Sandbox Code Playgroud)

我使用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
Run Code Online (Sandbox Code Playgroud)

我不知道错误是什么......

shi*_*ara 657

您需要使用PostgreSQL的头安装postgreSQL dev包

sudo apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)

  • `sudo apt-get install libpq-dev`为我工作 (12认同)
  • 对于Cent/RedHat风格的发行版,你需要的包是`yum install postgresql-devel` (5认同)
  • 对于那些刚接触Ubuntu的人来说,我真的很新用`sudo apt-get install aptitude` :) (3认同)

小智 39

在阅读并th for for for for,,and and and and and and and and and and and and and and and and and and and and and and and and with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with with 1.8.15,rails 3.0.1,postgres 8.4.10):

gem install pg  --   --with-pg-lib=/usr/lib   
Run Code Online (Sandbox Code Playgroud)

结果:

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...  
Run Code Online (Sandbox Code Playgroud)

{是啊 - 终于成功了!! !! !请注意,在我的Ubuntu/Postresql安装中,运行pg_config的输出缺少LIBS变量中的项目-lpq!

为什么在某些地方从pq切换到pg - 让新手感到困惑?

我仍然不明白的是双重设置 - 和 - 用(选项但我无论如何都超出了我的深度

  • “-”通常用于将第一个命令的参数与第二个命令(在这种情况下为extmod的configure脚本)分开 (2认同)

Xan*_*der 29

我在Ubuntu 12.10上并运行此命令:

apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)

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


小智 25

需要添加包

sudo apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)

在RoR中安装pg gem


小智 24

在Ubuntu这对我有用,我希望能帮到你:

sudo apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)

gem install pg  --   --with-pg-lib=/usr/lib 
Run Code Online (Sandbox Code Playgroud)


小智 22

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

sudo apt-get install libpq-dev build-essential
Run Code Online (Sandbox Code Playgroud)


小智 16

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

首先卸载所有postgres包,然后运行这些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
Run Code Online (Sandbox Code Playgroud)

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


Got*_*tey 10

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


vek*_*lov 9

对于.RVM用户,它会更好:

rvmsudo gem install pg -- --with-pg-lib=/usr/lib 
Run Code Online (Sandbox Code Playgroud)

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


Mik*_*ell 6

如果您安装了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
Run Code Online (Sandbox Code Playgroud)

这终于在Ubunto 12.04上解决了我的问题.


小智 5

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

rvmsudo gem install pg -v '0.12.2' -- --with-pg-lib=/usr/include/postgresql
Run Code Online (Sandbox Code Playgroud)


ill*_*ist 5

试试这个

sudo apt-get install postgresql postgresql-contrib libpq-dev
Run Code Online (Sandbox Code Playgroud)

您应首先安装PG数据库服务器以安装客户端.然后,您安装客户端.

请参阅此博客文章,了解有关首次为Ruby on Rails开发设置PostGresSQL的信息.