问题描述
我刚刚升级到 Rails 3,在 MacPorts、gem 和数据库方面有些混乱需要整理.我扔掉了所有的宝石并重新安装它们.除了 pg gem 的要求外,一切似乎都很好.
I just upgraded to Rails 3 and had a bit of a mess with MacPorts, gems and databases to sort out. I threw out all the gems and installed them fresh. Everything seems to be OK except for the requirement of the pg gem.
创建一个新的 Rails 3 项目后,为 PostgreSQL 准备,服务器无法启动,抱怨缺少 pg gem.执行 bundle install
,它运行了一段时间,当然,在 pg gem 上失败了.
After creating a new Rails 3 project, prepared for PostgreSQL, the server would not start, complaining about the missing pg gem. Doing bundle install
, it chugged along for a while and, of course, fails on the pg gem.
Installing pg (0.10.0) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483: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
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/pg-0.10.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.10.0/ext/gem_make.out
from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `each'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `build_extensions'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:198:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/source.rb:95:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:55:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:44:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:8:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/cli.rb:225:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in `send'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in `dispatch'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/base.rb:389:in `start'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19
我在论坛和博客上发现的最常见的建议是(重新)安装 XCode 开发人员工具.它们已经在那里了,但我还是重新安装了它们,没有比上面更好的结果.
The most common suggestion I have found on forums and blogs is to (re)install the XCode developer tools. They were already there, but I reinstalled them anyway, with no better outcome than the above.
which ruby
说 /usr/bin/ruby
,ruby -v
说 ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
,如果那里有任何线索的话.
which ruby
says /usr/bin/ruby
, and ruby -v
says ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
, if there's any clue there.
欢迎指点.任何有助于解决此问题的缺失信息,我都会很乐意及时提供!
Pointers are welcome. Any missing information that would help figuring this out, I'll gladly and promptly provide!
我下载了 XCode,因为据说 DVD 版本已经坏了,而且有一段时间事情变得更好了.bundle install
开始谈论archflags",所以我这样做了:
I downloaded XCode since the DVD version is said to be broken and things went better for a while. bundle install
started talking about "archflags" instead, so I did:
sudo env ARCHFLAGS="-arch i386" bundle install
一切似乎都很顺利,直到启动 Rails 时,他说:
and things seemed to go fine, until starting Rails barfed, saying:
/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle, 9): no suitable image found. Did find: (LoadError)
/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: mach-o, but wrong architecture - /Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle
为了解决任何问题,我尝试了 bundle install
,并将 archflags 设置为 -arch x86_64
,但效果不佳:
Grappling for anything, I tried bundle install
with archflags set to -arch x86_64
, but it didn't go well:
*** Your PostgreSQL installation doesn't seem to have an architecture in common with the running ruby interpreter ([] vs. ["x86_64"])
I'll continue anyway, but if it fails, try setting ARCHFLAGS.
[...]
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
libpq 是我现在必须通过一些标志提供路径的东西吗?还是我完全出去吃午饭了?
Is libpq something I now have to supply a path to via some flags? Or am I completely out to lunch?
推荐答案
一般来说,Postgres 的 gem 包想知道 pg_config
隐藏在哪里,以便询问 Postgres 的安装.
Generally the gem bundles for Postgres want to know where pg_config
is hiding so they can ask about the Postgres installation.
使用 locate pg_config
查看您的 Mac 是否知道它的隐藏位置.
Use locate pg_config
to see if your Mac knows where it's hiding.
我使用 mappstack 安装了 Postgres 的副本,所以我的 Mac 说在以下位置有一个副本:
I installed a copy of Postgres using mappstack, so my Mac says there's a copy at:
/Applications/mappstack-1.2-3/postgresql/bin/pg_config
另一个在:
/Library/PostgreSQL/9.0/bin/pg_config
我不记得在 /Library/PostgreSQL/9.0
安装过,所以可能是 Snow Leopard 预装的,或者是我工作量太大时安装的,可能使用 EnterpriseDB 中的 Postgres 安装程序.
I don't remember installing the one at /Library/PostgreSQL/9.0
, so it might have been preinstalled by Snow Leopard, or I did it when under the influence of too much work, possibly using the Postgres installer from EnterpriseDB.
找到 pg_config
的位置后,尝试将该目录添加到 PATH 的开头,然后重新运行 gem 安装.或使用:
Once you've found the location of pg_config
try adding that directory to the start of your PATH and then rerun the gem install.
Or use:
export SQL_PATH=/Library/PostgreSQL/9.0
gem install pg -- --with-pg-config=$SQL_PATH/bin/pg_config
并尝试安装.如果其中任何一项工作都完成了.否则……
and try installing. If either of those work you're done. Otherwise...
安装程序可能想要的下一件事是访问 Postgres 标头,因此您查看 bin
目录的父目录,看看是否可以找到 include
目录.
The next thing the installers might want are access to the Postgres headers, so you look in the parent of the bin
directories, and see if you can find an include
directory.
之后,在该目录中查找 lib
目录.一旦您知道了这些位置,您应该拥有设置环境变量以完成安装程序所需的一切.您需要阅读安装程序的 README
或 INSTALL
文件并查看需要设置的内容.您将进行配置:
After that, look in that directory for a lib
directory. Once you know those locations you should have all you need to set your environment variables to let the installer complete. You'll need to read the README
or INSTALL
file of the installer and see what needs to be set up. You'll be configuring:
export include_dir=$SQL_PATH/include/
export lib_dir=$SQL_PATH/lib/
gem install pg -- --with-pgsql-include-dir=$include_dir --with-pgsql-lib-dir=$lib_dir
希望这会有所帮助.我的 Rails 3 和我的 Postgres 运行良好,使用了 mappstack Postgres 和 EnterpriseDB 版本,所以上面的信息应该能让你到达那里.
Hopefully that'll all help. I have Rails 3 and my Postgres running fine, using the mappstack Postgres and the EnterpriseDB versions, so the above info should get you there.
这篇关于安装 pg gem 失败,“mkmf.rb 找不到 ruby 的头文件"(Mac OSX 10.6.5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2