Rails:安装pg gem时出错

时间:2012-07-11 18:38:27

标签: ruby-on-rails postgresql

  

可能重复:
  Postgres - the last version 0.14.0 of the “pg” gem gives error

我是铁杆新手。我想使用PostgreSQL,因为Heroku也使用它,但我在安装pg gem时遇到了不好的时间。显然,有些文件丢失,无法创建Makefile?

我的宝石文件如下所示:

source 'https://rubygems.org'

gem 'rails', '3.2.6'
gem 'faker', '1.0.1'
gem 'pg', '0.12.2'
gem 'json'

group :development, :test do
  gem 'rspec-rails', '2.10.0'
end

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails', '2.0.0'

group :test do
  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails', '1.4.0'
end

当我运行bundle install时,我在安装pg gem时遇到以下错误:

    Installing pg (0.14.0) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in /Users/KennyGWang/.bundler/tmp/18833/gems/pg-0.14.0 for inspection.
Results logged to /Users/KennyGWang/.bundler/tmp/18833/gems/pg-0.14.0/ext/gem_make.out
An error occured while installing pg (0.14.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.0'` succeeds before bundling.

我使用自制软件brew install postgresql安装了postgresql,因此which psql给了我/usr/local/bin/psql

感谢任何帮助!

4 个答案:

答案 0 :(得分:66)

你在Mac上吗?如果是这样 - 最简单的方法是

  1. 确保您已安装Xcode(您可以从应用商店获取)
  2. 使用Homebrew
  3. brew install postgresql
  4. gem uninstall pg
  5. 应用程序根目录中的bundle installgem install pg

答案 1 :(得分:7)

安装postgresql的步骤

  1. 安装PostgreSQL及其库

    sudo apt-get install postgresql postgresql-contrib libpq-dev
    
  2. 安装后为postgresql创建用户

    sudo -u postgres createuser --superuser $USER
    

    sudo -u postgres createuser pgs_root
    
  3. 设置postgresql用户的用户密码

    sudo -u postgres psql postgres ( For psql prompt) postgres=# \passsword for ex.-      postgres=# \passsword pgs_root
    
  4. 配置postgresql.conf文件以使PostgreSQL侦听localhost或侦听外部IP或其他内容,将此行更改为IP或“localhost”

    gedit /etc/postgresql/8.4/main/postgresql.conf listen_addresses = 'localhost'
    

  5. 与mysql查询浏览器一样,postgresql有一个名为pgadmin的GUI。要安装,请运行此命令

    sudo apt-get install pgadmin3
    

答案 2 :(得分:4)

尝试包含此而不是pg

gem install postgres-pr

gem install ruby-pg

修改

你有没有这样做过?

$ sudo apt-get install postgresql

$ rails new pg -d postgres
  

http://www.funonrails.com/2011/03/getting-started-with-rails-3-postgres.html

答案 3 :(得分:0)

您是否已根据您所包含的错误中的建议检查了日志mkmf.log?

由于某种原因无法创建Makefile,可能缺少  必要的库和/或标题。检查mkmf.log文件以获取更多信息  细节。您可能需要配置选项。