为什么pg gem不会安装?

时间:2011-10-09 10:12:58

标签: ruby-on-rails postgresql pg

我刚刚在我的mac上安装了PostgreSQL 9.x,并且在将bundle install添加到我的gemfile后尝试运行pg时,我得到:

Installing pg (0.11.0) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:529:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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=/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


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/pg-0.11.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.11.0/ext/gem_make.out
from /Library/Ruby/Site/1.8/rubygems/installer.rb:482:in `each'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:482:in `build_extensions'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:156:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/source.rb:101:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/rubygems_integration.rb:78:in `preserve_paths'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/source.rb:91:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/installer.rb:58:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/rubygems_integration.rb:93:in `with_build_args'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/installer.rb:57:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/installer.rb:49:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/installer.rb:8:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/cli.rb:222:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/vendor/thor/task.rb:22:in `send'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/vendor/thor/task.rb:22:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/vendor/thor.rb:246:in `dispatch'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/lib/bundler/vendor/thor/base.rb:389:in `start'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.15/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19

1 个答案:

答案 0 :(得分:2)

线索在:

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

您需要将其指向pg_config文件。

所以找到pg_config文件的位置并运行它:

gem install pg --with-pg-config=/path/to/pg_config