关于rails上的ruby:PostgreSQL的pg gem不会安装在OS X上

PostgreSQL's pg gem won't install on OS X

我已经在互联网上看了所有的解决方案,重新安装了一切,但仍然没有......当我做宝石安装时,我得到:

Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

1
  /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb --with-pgsql->lib=/usr/local/Cellar/postgresql/9.2.1/lib --with-pg->config=/usr/local/Cellar/postgresql/9.2.1/bin/pg_config

Using config values from /usr/local/Cellar/postgresql/9.2.1/bin/pg_config
checking for libpq-fe.h... * 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
--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/henriquedubugras/.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
/Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:506:in
try_cpp'
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:970:in block in find_header'
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in
block in checking_for'
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in block (2 levels) in postpone'
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in
open'
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in block in postpone'
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in
open'
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in postpone'
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in
checking_for'
from /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:969:in find_header'
from extconf.rb:41:in
'

Gem files will remain installed in /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/pg-0.14.1 for inspection.
Results logged to /Users/henriquedubugras/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/pg-0.14.1/ext/gem_make.out

我尝试设置pg_config路径,安装了我的xcode,安装了xcode的命令行工具,我的ruby版本是由RVM安装的1.9.3。

我的mac是OS X Mountain Lion

多谢你们!


你错过了Postgres客户端库头文件(libpq-fe.h)。 在Debian中,包名为libpq-dev。 我根本不了解Mac包装,但如果没有Mac存储库构建PG源客户端库可以工作。


我建议安装rvm https://rvm.io/rvm/install
然后运行rvm要求。 这将安装所有必需的软件包,你可能会在安装rails之后错过"gcc49"并且非常适合安装postgres。 我会建议postgresapp或postgresql。