Mountain Lion上的pg gem’0.14.0’失败了

我刚从OS X Lion升级到OS X Mountain Lion。 我的铁路环境大部分都保持着机智。

我必须做的唯一步骤才能让事情恢复到良好状态: – 安装XCode 4.4 – 安装XCode 4.4命令行工具 – 安装gcc-4.2

一切顺利。

这是问题,当我运行bundle install时几乎所有的gem都安装正确,除了我需要的最重要的一个 – postgresql gem’pg’。

它特别适用于0.12.2以上的版本。

我正在使用ruby 1.9.3p125。

我可以成功地获取0.12.2 pg gem以及下面的版本,但是它们给了我分段错误(我猜是因为我正在使用的ruby版本)。

因此,这让我相信它特定于pg gem,而不是我的整体环境看到其他gem安装正常。

我也尝试重新安装Postgresql以确保我的postgres环境没问题,并且在这方面似乎很好。

有没有人能够安装’pg’gem版0.13.0或更高版本(更优选0.14.X)?

这是我的堆栈跟踪:

Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /Users/caseyli/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb checking for pg_config... yes Using config values from /usr/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... yes checking for PQconnectionUsedPassword()... yes checking for PQisthreadsafe()... yes checking for PQprepare()... yes checking for PQexecParams()... yes checking for PQescapeString()... yes checking for PQescapeStringConn()... yes checking for PQescapeLiteral()... yes checking for PQescapeIdentifier()... yes checking for PQgetCancel()... yes checking for lo_create()... yes checking for pg_encoding_to_char()... yes checking for pg_char_to_encoding()... yes checking for PQsetClientEncoding()... yes checking for PQlibVersion()... yes checking for PQping()... yes checking for rb_encdb_alias()... yes checking for rb_enc_alias()... no checking for PGRES_COPY_BOTH in libpq-fe.h... no checking for struct pgNotify.extra in libpq-fe.h... yes checking for unistd.h... yes checking for ruby/st.h... yes creating extconf.h creating Makefile make compiling pg.c pg.c: In function 'pg_s_library_version': pg.c:273: warning: implicit declaration of function 'PQlibVersion' pg.c: In function 'Init_pg_ext': pg.c:384: error: 'PQPING_OK' undeclared (first use in this function) pg.c:384: error: (Each undeclared identifier is reported only once pg.c:384: error: for each function it appears in.) pg.c:386: error: 'PQPING_REJECT' undeclared (first use in this function) pg.c:388: error: 'PQPING_NO_RESPONSE' undeclared (first use in this function) pg.c:390: error: 'PQPING_NO_ATTEMPT' undeclared (first use in this function) make: *** [pg.o] Error 1 Gem files will remain installed in /Users/caseyli/.rvm/gems/ruby-1.9.3- p125@elliottfarmequipment/gems/pg-0.14.0 for inspection. 

Deefour的评论得到了它! 这是我安装PostgreSQL的方式。

我使用PostgreSQL一键安装程序,我猜测它没有为Mountain Lion正确设置libpq。

另一方面,Homebrew将为操作系统正确构建它。

通过自制软件安装postgres后

 brew install postgresql 

我能够安装我的gem没问题。

谢谢大家!

问题是pg_config的位置。 如果你使用一键安装程序,它在/Library/PostgreSQL/9.2/bin/pg_config中,所以这将构建你的gem就好了:

env ARCHFLAGS =“ – arch x86_64”gem install pg – –with-pg-config = / Library / PostgreSQL / 9.2 / bin / pg_config

我有完全相同的问题; 与您发布的相同的堆栈跟踪。

MRI 1.9.3-p286 / OS X 10.8.2 / Postgres 9.0.4 with homebrew。

我通过简单地解决它:

 $ brew update $ brew upgrade postgresql $ bundle 

希望它适用于其他人。

重新安装ruby修复了升级到Mountain Lion后我遇到的类似问题

 rvm reinstall 1.9.3 

注意:还运行以下操作,因为默认版本似乎重置

 rvm --default 1.9.3 

作为参考,我发布了我在下面看到的错误

 gem install pg Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with pg=/usr/local/Cellar/postgresql/9.1.4/bin checking for pg_config... yes Using config values from /usr/local/bin/pg_config checking for libpq-fe.h... no Can't find the 'libpq-fe.h header *** extconf.rb failed *** 

Mac附带了一个过时的预建PostgreSQL客户端安装和它附带的pg_config文件与任何新的PostgreSQL服务器和客户端安装冲突。

使用完全限定的文件名pg_config安装ruby gem会覆盖pg_config的默认已知位置,并且安装成功。

EnterpriseDB的一个单击安装程序的pg_config的当前位置:/ Library / PostgreSQL / bin / pg_config

这个命令最终对我有用。

CrashMX2$ gem install pg -- --with-pg-config=/Library/PostgreSQL/bin/pg_config

我有同样的问题,但重新安装postgresql与homebrew没有解决它。 但是,这个命令为我做了:

 sudo env ARCHFLAGS="-arch x86_64" gem install pg 

我能够通过从Heroku安装Postgres.app并删除我现有的postgresql安装来使其工作。 你可以在这里下载应用程序:

http://postgresapp.com/

 brew remove postgresql bundle install 

如果你没有使用brew,这里有一个链接到Postgres.app的更多卸载文档

http://postgresapp.com/documentation#toc_16

我只是通过这张票获得了我的运行:

当我运行bundle install时,如何为gem安装传递参数?

 bundle config build.pg --with-pg-config=/path/to/pg_config bundle install 

就像Matt,Ranjan和Peter Mellett都说的那样,你必须获得正确的pg_config位置,而Mountain Lion有一个不同的位置,似乎不能很好地与rubygems,所以如果你发现你的旧版本像

 /Library/PostgreSQL/bin/pg_config 

然后你可以在安装前在bundle配置中设置它。

我的情况是从Lion升级到Mountain Lion。

Homebrew在/usr/local/bin/pg_ctl安装了pg_ctl ,所以对我的命令是:

 env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_ctl 

那些使用Kubuntu 13.04并用一键工具安装pg的人,pg config在其他文件夹中,所以命令:

 gem install pg -- --with-pg-config=/opt/PostgreSQL/9.3/bin/pg_config