【问题标题】:Can't install the pg gem [closed]无法安装 pg gem [关闭]
【发布时间】:2013-05-22 22:31:03
【问题描述】:

在 Mac OS X 10.6.8 上,尝试gem install pg 时出现以下错误。试图将我的 Rails 网站推送到 Heroku。非常标准的 Ruby 1.9.3p194 安装。

$ cat /Users/me/.rvm/gems/ruby-1.9.3-p194\@ucode/gems/pg-0.15.1/ext/gem_make.out 
/Users/me/.rvm/rubies/ruby-1.9.3-p194/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=/Users/me/.rvm/rubies/ruby-1.9.3-p194/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

我以前从来不需要在本地安装 postgresql。我也需要安装数据库吗?事实上,我什至不打算在本地使用 postgresql,只在 Heroku 上使用

【问题讨论】:

  • “我什至不打算在本地使用 postgresql”是一个非常糟糕的主意,使用不同的数据库进行开发和部署是一个非常常见的痛苦来源。不,像 ActiveRecord 这样的 ORM 不会使您免受数据库差异的影响。因此,如果您计划在 PostgreSQL 之上部署,请在本地安装 PostgreSQL 并使用 PostgreSQL 进行开发。
  • 可能是duplicated
  • gem 有一个本地 C 扩展,它需要 PGSQL 安装附带的 PostgreSQL (PGSQL) 头文件。我非常怀疑您之前不需要安装 PGSQL,也许您在不知情的情况下安装了它。使用 Homebrew 安装非常简单:brew install postgresql 并按照屏幕上的说明进行操作。

标签: ruby postgresql gem ruby-1.9.3 pg


【解决方案1】:

构建输出的第一行告诉您出了什么问题以及该怎么做:

No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config

所以.... 传递 --with-pg-config=/wherever/your/pg_config 或将其添加到 PATH 以便构建可以找到它。

我也强烈反对 mu 的评论;使用一个数据库进行本地测试并使用另一个数据库进行远程测试是痛苦、痛苦和部署错误的秘诀。如果 SQL 真的足够一致且足够标准以使其工作,那就太好了,但现实情况却不同。

【讨论】:

    猜你喜欢
    • 2013-02-20
    • 2015-03-16
    • 1970-01-01
    • 2012-03-28
    • 2016-03-27
    • 2020-02-28
    相关资源
    最近更新 更多