Gem gem install pg 错误 问题出在哪里呢?

shin · 2012年08月17日 · 最后由 railsbug 回复于 2013年03月16日 · 7112 次阅读

我用 ubuntu 系统,刚刚在安装 pg 时报错;如下信息,我在网上搜索了一下 找到http://effectif.com/databases/installing-pg-gem-on-mac 这个方法,我也找到了/usr/lib/postgresql/9.1/bin 的目录,也用了 PATH=$PATH:/usr/lib/postgresql/9.1/bin sudo gem install pg 还是不行,求助!

第一次报错

shin@ubuntu:~/rails-project/jiefu$ gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /home/shin/.rvm/rubies/ruby-1.9.2-p320/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... *** 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
    --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/shin/.rvm/rubies/ruby-1.9.2-p320/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
/home/shin/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.

第二次报错

PATH=$PATH:/usr/lib/postgresql/9.1/bin sudo gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:2:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/pg-0.14.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/pg-0.14.0/ext/gem_make.out

You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev

@huacnlee 谢谢回复,好快啊!done!

同样遇到这个问题,同样解决了,Thx

You need to install postgresql-server-dev-X.Y

你本地没有安装 postgresql 这个数据库啊

以前没有用过 linux 的时候,就知道它的命令行很吓人,就怕没有 windows 的界面,就怕 linux 不是普通人用的,等等。 其实被误导了,不过主要怪自己没有亲自尝试。 这一年用下来,才发现,linux 的提示很多时候比 windows 还要好。 以前总觉得.NET 有 msdn,很强大。用来 python,ruby 才发现,python 的文档,ruby 的文档,比 msdn 要好不知道多少倍,而且很实用,介绍很详细。给出的示例代码,很快就可以看明白。 不像 msdn,看似很多东西,但是很多都是没有用的代码,不相关的,一大丢,很难找到你想要的介绍。 哈哈~~~

7 楼 已删除

#1 楼 @huacnlee 我用的是 fedora 的系统,yum install postgresql-server-dev-X.Y 不能安装,怎么解决呢?

冒昧问一下,pg 是什么来的?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号