Rails:安装pg gem时出错

可能重复:
Postgres – “pg”gem的最后一个版本0.14.0给出了错误

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

我的gem文件如下所示:

 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. 

我用homebrew brew install postgresqlbrew install postgresql ,因此which psql给我/usr/local/bin/psql

任何帮助表示赞赏!

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

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

安装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' 

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

 sudo apt-get install pgadmin3 

尝试包含此而不是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

你有没有检查过日志mkmf.log,因为你所包含的错误是推荐的?

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