新手问题 [已解决] gem install pg 报错

springwq · 2013年12月08日 · 最后由 zengfengbo 回复于 2017年01月05日 · 11957 次阅读

目前 升级了 RVM, Homebrew, 还是安装不了,

切换到 ruby-1.9 也是报错。

前几天我的这个 project-template 还是正常的,今天准备从头再来一次,bundle install 就一直过不去,提示无法安装 pg -v '0.15.0'

RROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /Users/WuQi/.rvm/rubies/ruby-2.0.0-p247/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.

Gemfile

source 'https://rubygems.org'

gem 'rails', '4.0.0'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'bootstrap-sass', '~> 2.3.2.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'

group :doc do
  gem 'sdoc', require: false
end

group :development do
  gem 'quiet_assets'
  gem 'pry'
  gem 'sqlite3'
end

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

看系统好像是 Mac 吧,建议使用 Homebrew 重新安装一遍 Postgresql。然后再安装 pg 的 gem。这个 gem 依赖 postgresql 的一些库文件。

ubuntu ???

这个问题困扰我到死!!!ubuntu 上就是缺这个 head lib。。。。欲哭无泪啊。。。

我用which pg_config 找不到任何东西,貌似我的电脑没有这个,系统是 MAC. 等会升级下 XCODE 再看看

如果使用Postgres.app,可以参考下 http://postgresapp.com/documentation 中的 Troubleshooting,网页最下面。里面给出了 gem 无法安装的解决方法。

#5 楼 @chunlea 谢谢!问题已解决。我用 brew install Postgresql 之后,再 gem install pg, 这次 OK 了, budle install 也通过了。 现在想想,前几天没出问题,是因为我当时参照教学视频里 运行了 bundle install --without production, 当时根本没装 pg 这个 gem。 今天下午,2-3 小时,都在填这个坑。。

#6 楼 @springwq 用你的方法,出现
Can't find the PostgreSQL client library (libpq) .. Mac 10.9.4

补充:ARCHFLAGS="-arch x86_64" gem install pg 可行

如果在 mac 上安装了 Postgres.app 的话

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.6/bin/pg_config
需要 登录 后方可回复, 如果你还没有账号请 注册新账号