我使用的是Ruby on Rails 3.1的预版本.我喜欢使用PostgreSQL,但问题是安装pg gem.它给了我以下错误:

$ 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版本中是这样的:

...
/usr/include/postgresql/libpq-fe.h
...

因此,请try 为您的操作系统安装libpq-dev或同等产品:

  • 对于Ubuntu/Debian系统:sudo apt-get install libpq-dev
  • Red Hat Linux(RHEL)系统上:yum install postgresql-devel
  • Mac Homebrew:brew install postgresql
  • 对于Mac MacPorts PostgreSQL:gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
  • OpenSuse:zypper in postgresql-devel
  • ArchLinux:pacman -S postgresql-libs

Ruby-on-rails相关问答推荐

在控制器操作中适当使用ActiveModel Dirty

Rails HMAC - 使用应用程序机密作为加密密钥

ruby on rails 中的自定义关联

rails s和bundle exec rails s有什么区别?

在允许用户使用设计(rails)登录之前判断用户是否处于活动状态

如何配置设计以使用自定义邮箱布局?

如何在我的 rails 应用程序中测试 ActiveRecord::RecordNotFound?

从 before_action 中排除控制器

可能在rails中有多态has_one关系?

使用 RSpec 2 关闭一个规范的事务性固定装置

Rails:使用 gem 卸载特定版本的库

如何让 ActiveAdmin 使用强参数?

在 Rails 中,在特定时区创建特定时间(不是现在)的最佳方式是什么?

如何设置 MiniTest?

使用redirect_to后如何停止控制器执行? (使用导轨)

没有路由匹配缺少必需的键:[:id]

使用设计创建一个用户显示页面

Rails.cache 在测试之间被清除了吗?

如何删除特殊字符?

为什么 rails bootstrap 这么慢,我该怎么办?