安装 pg gem 失败,“mkmf.rb 找不到 ruby​​ 的头文件”(Mac OSX 10.6.5)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4393189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:50:31  来源:igfitidea点击:

Failing installing pg gem, "mkmf.rb can't find header files for ruby" (Mac OSX 10.6.5)

ruby-on-railsrubypostgresqlrubygems

提问by npup

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 并且对 MacPorts、gems 和数据库有点混乱需要整理。我扔掉了所有的宝石并重新安装了它们。除了 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.

创建新的 Rails 3 项目后,为 PostgreSQL 准备,服务器无法启动,抱怨缺少 pg gem。执行bundle install,它缓慢前进了一段时间,当然,在 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

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.

我在论坛和博客上发现的最常见的建议是(重新)安装 XCode 开发人员工具。他们已经在那里了,但我还是重新安装了它们,没有比上面更好的结果。

which rubysays /usr/bin/ruby, and ruby -vsays ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0], if there's any clue there.

which ruby/usr/bin/ruby,然后ruby -vruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0],如果那里有任何线索的话。

Pointers are welcome. Any missing information that would help figuring this out, I'll gladly and promptly provide!

欢迎指点。任何有助于解决此问题的缺失信息,我都会很乐意并及时提供!



I downloaded XCode since the DVD version is said to be broken and things went better for a while. bundle installstarted talking about "archflags" instead, so I did:

我下载了 XCode,因为据说 DVD 版本坏了,而且情况好转了一段时间。bundle install开始谈论“archflags”,所以我做了:

sudo env ARCHFLAGS="-arch i386" bundle install

and things seemed to go fine, until starting Rails barfed, saying:

一切似乎都很顺利,直到启动 Rails 时吐槽,说:

/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

Grappling for anything, I tried bundle installwith archflags set to -arch x86_64, but it didn't go well:

为解决任何问题,我尝试 bundle install将 archflags 设置为-arch x86_64,但效果不佳:

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

Is libpq something I now have to supply a path to via some flags? Or am I completely out to lunch?

libpq 是我现在必须通过某些标志提供路径的东西吗?还是我完全出去吃午饭了?

采纳答案by the Tin Man

Generally the gem bundles for Postgres want to know where pg_configis hiding so they can ask about the Postgres installation.

通常 Postgres 的 gem 包想知道pg_config隐藏在哪里,以便他们可以询问 Postgres 的安装。

Use locate pg_configto see if your Mac knows where it's hiding.

使用locate pg_config,看看你的Mac知道它的藏身何处。

I installed a copy of Postgres using mappstack, so my Mac says there's a copy at:

我使用mappstack安装了 Postgres 的副本,所以我的 Mac 说有一个副本:

/Applications/mappstack-1.2-3/postgresql/bin/pg_config

and another at:

另一个在:

/Library/PostgreSQL/9.0/bin/pg_config

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.

我不记得安装一个在/Library/PostgreSQL/9.0,所以它可能已经被雪豹预装,或者我做了太多的工作的影响时,可能使用从Postgres的安装EnterpriseDB公司

Once you've found the location of pg_configtry adding that directory to the start of your PATH and then rerun the gem install. Or use:

找到位置后,pg_config尝试将该目录添加到 PATH 的开头,然后重新运行 gem install。或使用:

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

并尝试安装。如果其中任何一项工作都完成了。除此以外...

The next thing the installers might want are access to the Postgres headers, so you look in the parent of the bindirectories, and see if you can find an includedirectory.

安装人员接下来可能想要访问 Postgres 头文件,因此您可以查看bin目录的父目录,看看是否可以找到一个include目录。

After that, look in that directory for a libdirectory. 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 READMEor INSTALLfile of the installer and see what needs to be set up. You'll be configuring:

之后,在该目录中查找lib目录。一旦您知道这些位置,您就应该拥有设置环境变量以让安装程序完成所需的一切。您需要阅读安装程序的READMEINSTALL文件并查看需要设置的内容。您将配置:

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

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.

希望这一切都会有所帮助。我有 Rails 3 和我的 Postgres 运行良好,使用 mappstack Postgres 和 EnterpriseDB 版本,所以上面的信息应该能让你到达那里。

回答by Yuta

I encountered this error when I tried to install rails by gem on CentOS 6.3.

我在 CentOS 6.3 上尝试通过 gem 安装 rails 时遇到了这个错误。

After googling a bit, I found a quick fix: installing the ruby-devel package.

在谷歌上搜索了一下之后,我找到了一个快速解决方法:安装 ruby​​-devel 包。

sudo yum install ruby-devel

After that, everything worked fine.

之后,一切正常。

回答by Paul Cantrell

This worked for me on OS X 10.6.6, with PostgreSQL 9.0.1 installed from the source code:

这在 OS X 10.6.6 上对我有用,从源代码安装了 PostgreSQL 9.0.1:

export PATH=/usr/local/psql/bin:$PATH
export ARCHFLAGS='-arch x86_64'
gem install pg

You'll likely need to edit that PATH to match your postgres install location.

您可能需要编辑该 PATH 以匹配您的 postgres 安装位置。

回答by Josh

I've got postgres 1.9.0 installed via macports. OS X 10.5 PPC

我已经通过 macports 安装了 postgres 1.9.0。OS X 10.5 每次点击付费

This worked for me:

这对我有用:

gem install pg -- --with-pg-lib=/opt/local/lib/postgresql90 --with-pg-include=/opt/local/include/postgresql90

Good luck!

祝你好运!

回答by Steve

Generally the gem bundles for Postgres want to know where pg_config is hiding . . .

通常 Postgres 的 gem 包想知道 pg_config 隐藏在哪里。. .

Right - this could be the trick. If you just installed PostgreSQL and added it to your path, and did "bundle install" in an old shell, it won't be able to find pg_config. If that's the case, just get a new shell and try again. Otherwise, follow the steps above to find it and get it seen by bundler.

对 - 这可能是诀窍。如果您刚刚安装了 PostgreSQL 并将其添加到您的路径中,并在旧 shell 中进行了“捆绑安装”,它将无法找到 pg_config。如果是这种情况,只需获取一个新外壳并重试。否则,请按照上述步骤找到它并让捆绑程序看到它。

The macports install for postgresql83 works fine and plays nicely with rails right out of the box - that's another way to do it.

postgresql83 的 macports 安装工作正常,开箱即用,可以很好地与 Rails 配合使用 - 这是另一种方法。

回答by Sean Bachelder

I just spent a good deal of time getting this to work tonight. I saw a similar error to this:

我只是花了很多时间让这个今晚工作。我看到了类似的错误:

Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***

I tried different gem install variations:

我尝试了不同的 gem 安装变体:

gem install pg -- --with-pg-config=/Library/PostgreSQL/9.1/bin/ --with-pg-lib=/Library/PostgreSQL/9.1/lib/ --with-pg-include=/Library/PostgreSQL/9.1/include/

But finally what worked for me was:

但最终对我有用的是:

gem install pg -- --with-pg-dir=/Library/PostgreSQL/9.1/

Also, before that I updated rvm (rvm get head) and reinstalled ruby (rvm --force install 1.9.2). Not sure if this helped or not, but it might be worth trying if you still hit issues

另外,在此之前,我更新了 rvm(rvm get head)并重新安装了 ruby​​(rvm --force install 1.9.2)。不确定这是否有帮助,但如果您仍然遇到问题,可能值得尝试

回答by markquezada

You might want to try going with homebrewfor installing postgres (brew install postgres) and Ruby Version Managerfor installing and maintaining ruby and ruby gems.

您可能想尝试使用homebrew来安装 postgres ( brew install postgres) 和Ruby Version Manager来安装和维护 ruby​​ 和 ruby​​ gems。

It'll leave your default versions (installed with OSX) untouched and give you more flexibility. For example, you could have different rails apps using rails 2 or 3 with ruby 1.8.7 and 1.9.2 all installed on the same system without problems.

它将保留您的默认版本(与 OSX 一起安装)不变,并为您提供更大的灵活性。例如,您可以使用 rails 2 或 3 以及 ruby​​ 1.8.7 和 1.9.2 安装不同的 rails 应用程序,所有这些应用程序都安装在同一系统上而不会出现问题。

回答by ethiyo

This worked for me:

这对我有用:

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

回答by iammyr

All the suggestions here and around the Web were incomplete for me, until I run the following on CentOS 6.6:

这里和网上的所有建议对我来说都是不完整的,直到我在 CentOS 6.6 上运行以下内容:

wget -c ftp://mirror.switch.ch/pool/4/mirror/scientificlinux/6.3/x86_64/updates/security/kernel-devel-2.6.32-504.1.3.el6.x86_64.rpm && sudo yum install kernel-devel-2.6.32-504.1.3.el6.x86_64.rpm
wget -c ftp://mirror.switch.ch/pool/4/mirror/scientificlinux/6.6/x86_64/updates/security/kernel-headers-2.6.32-504.30.3.el6.x86_64.rpm && sudo yum install kernel-headers-2.6.32-504.30.3.el6.x86_64.rpm
sudo yum groupinstall "Development Tools" "Development Libraries" 
sudo yum -y install gcc gcc-c++ git ruby ruby-devel rubygems libvirt-devel mysql-devel postgresql-devel openssl-devel libxml2-devel sqlite-devel libxslt-devel zlib-devel readline-devel tar make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel ruby193-ruby-doc ruby193-ruby-devel ruby193-build
curl -L get.rvm.io | bash -s stable && source $HOME/.rvm/scripts/rvm && rvm requirements

回答by monteirobrena

Install Postgres.app:

安装 Postgres.app:

http://postgresapp.com/

http://postgresapp.com/

Verify what version was installed:

验证安装的版本:

$ ls /Library/PostgreSQL/
# 9.4

Export the SQL_PATH:

导出SQL_PATH

export SQL_PATH=/Library/PostgreSQL/9.4

Install pg:

安装pg

gem install pg -- --with-pg-config=$SQL_PATH/bin/pg_config