安装Mountain Lion后无法安装postgresql gem

3

我一直在尝试将我的Rails开发环境从Lion升级到Mountain Lion,但已经有一段时间了。问题在于安装pg-0.14.0(postgresql)gem。

我尝试了这篇文章中的方法,但没有成功。我尝试使用Homebrew卸载Postgres,然后重新安装它,但仍然无法解决问题。如果我尝试安装这个gem,我会收到以下错误提示:

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
checking for pg_config... yes 
Using config values from /usr/local/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... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)

*** 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.

我该在哪里找到 mkmf.log文件?有人能给我关于如何再次安装pg gem的建议吗?

更新 我使用以下命令找到了我的mkmf.log文件:

find / -name mkmf.log 2>/dev/null

有几个xcrun调用失败,例如下面的调用:

have_library: checking for PQconnectdb() in -llibpq... -------------------- no

"xcrun cc -o conftest -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/postgresql/9.1.4/include -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib -L. -arch i386 -arch x86_64 -L/usr/local/Cellar/postgresql/9.1.4/lib -lruby -llibpq -lpthread -ldl -lobjc " ld: library not found for -llibpq clang: error: linker command failed with exit code 1 (use -v to see invocation)

为什么运行xcrun时出现错误?有人见过这种情况吗?

谢谢!

4个回答

2
错误信息已经明确地提示了问题所在:
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)

它无法找到libpq,或者尝试编译测试程序并链接到它的测试失败了。由于它能找到/usr/local/bin/pg_config,所以它应该知道Pg库和头文件的位置,因此问题可能在测试编译中出现错误。
要了解更多信息,您需要检查mkmf.log。运行:
find . -name mkmf.log

从你运行gem install命令的目录中,可能会找到它。请使用其内容更新您的帖子。

感谢您的回复。运行 gem install pg -v '0.14.0' 可以无错误地安装宝石。然而,运行 bundle install 后出现了我发布的错误信息。当我试图在运行上述两个命令的相同目录中查找 mkmf.log 文件时,它没有被找到。 - Nick
@Nick,恐怕你的Ruby + Mac OS X知识范围已经超出了我的能力。试着查找一下bundle命令是否在某个临时编译目录中运行。如果你愿意等待,可以运行 find / -name mkmf.log 2>/dev/null 命令搜索整个系统,并抑制权限错误。 - Craig Ringer

2
我最终解决了这个问题。我使用RVM卸载了Ruby并重新安装了1.9.3版本,这使我能够顺利运行“bundle install”。我检查了所有的gem都已加载(gem list)。然而,在这一点上,我的Rails应用程序无法定位Postgres套接字文件。同样的问题在这里详细描述。与其定位postgresql.conf文件,更改其权限并进行编辑,我只是卸载了当前版本的Postgres,并从PostGres下载了最新的一键安装程序。当我再次运行安装程序时,它检测到其他PostGres安装并对其进行了更新。这为我更新了配置,一切都恢复正常了。
希望这可以帮助其他升级到Mountain Lion的可怜Rails开发者 :)

0

我也曾经为此苦苦挣扎了几个小时,但在我的设置中找不到任何可用的东西。

最终我使用了postgres.app。这是由Heroku发布的Postgres打包版本。他们说这是“在Mac上运行postgreSQL的最简单方法”。根据我的经验,这是真的!

只需将其放入应用程序文件夹中,你就完成了!(我只需要重新启动以释放端口5432)。

顺便说一句:他们还发布了一个名为Induction的应用程序来管理和查询你的数据库,但目前在Mountain Lion中无法使用。


这对我没用。实际上,当我运行它时似乎什么也没有发生。也许是因为我已经安装了Postgresql? - Nick
你的菜单栏上有小象图标吗?如果有,请点击它。你看到了什么? - Pierre

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接