【问题标题】:Rails: Error installing pg gem [duplicate]Rails:安装pg gem时出错[重复]
【发布时间】:2012-07-11 10:59:24
【问题描述】:

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

我是 Rails 新手。我想使用 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.

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

感谢任何帮助!

【问题讨论】:

标签: ruby-on-rails postgresql


【解决方案1】:

您使用的是 Mac 吗?如果是这样 - 最简单的方法是

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

【讨论】:

  • 只是关于#1 的注释。为了使 postgresql 公式能够正常工作,安装 Xcode 并正常工作非常重要。编译器用于构建 PostgreSQL 源代码。
  • 在 Mac OSX Mountain Lion (10.8.3) 上为我工作。
  • 在 Mavericks OSX 10.9.2 上工作,谢谢!
  • 我试过这个,但似乎对我不起作用。这最终成为为我修复它的解决方案stackoverflow.com/a/26609483/1438478
  • 只是为了补充这一点,因为我在搜索 Google 时遇到了它,我在 OSX Yosemite 上遇到了类似的问题:以上对我不起作用,但这样做:stackoverflow.com/a/7497725/1945990
【解决方案2】:

安装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 --set "user=$USER"
    postgres=# \passsword :user
    

    sudo -u postgres psql postgres
    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

【讨论】:

    【解决方案3】:

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

    【讨论】:

    • "sudo gem install ruby​​-pg" 不起作用,但第一个起作用了。我仍然错过了这个:“检查 -lpq 中的 PQconnectdb()...否”我需要 pg gem 来运行“rake db:migrate”!
    【解决方案4】:

    您是否按照您包含的错误中的建议检查了日志 mkmf.log?

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-21
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-04
      • 2016-05-02
      • 2014-08-20
      相关资源
      最近更新 更多