ruby 在 OSX 10.9 Maverick 上安装 Nokogiri 时出错?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19643153/
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-06 06:16:09  来源:igfitidea点击:

Error to install Nokogiri on OSX 10.9 Maverick?

rubymacosnokogirilibxml2osx-mavericks

提问by squiter

I upgraded my OSX (Lion) to Mavericks and I can't install Nokogiri for my projects.

我将 OSX (Lion) 升级到 Mavericks,但无法为我的项目安装 Nokogiri。

I already install XCode 5.0.1, Command Line Tools (using xcode-select --install), and already installed libxml2 from Homebrew and I am still having problems.

我已经安装了 XCode 5.0.1、命令行工具(使用xcode-select --install),并且已经从 Homebrew 安装了 libxml2,但我仍然遇到问题。

The error is:

错误是:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb
checking for libxml/parser.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/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-iconv-dir
    --without-iconv-dir
    --with-iconv-include
    --without-iconv-include=${iconv-dir}/include
    --with-iconv-lib
    --without-iconv-lib=${iconv-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-pkg-config
    --without-pkg-config
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-libiconv-config
    --without-libiconv-config
/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
    from extconf.rb:116:in `<main>'


Gem files will remain installed in /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9 for inspection.
Results logged to /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9/ext/nokogiri/gem_make.out
An error occured while installing nokogiri (1.5.9), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.

I installed libxml2, libxslt and libiconv from Homebrew, and set the params to install Nokogiri, but don't work too.

我从 Homebrew 安装了 libxml2、libxslt 和 libiconv,并设置了参数来安装 Nokogiri,但也不起作用。

I can't find what's wrong in my enviroment, can you help me?

我找不到我的环境有什么问题,你能帮我吗?

采纳答案by squiter

I found this log and saw that gcc-4.2 was not found:

我找到了这个日志,看到没有找到gcc-4.2:

package configuration for libxslt
cflags: -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2

package configuration for libxml-2.0
cflags: -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxml2

package configuration for libiconv is not found
"/usr/bin/gcc-4.2 -o conftest -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/ruby/backward -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1 -I. -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 -I/usr/local/Cellar/libiconv/1.14/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/include -I/Users/ericcamalionte/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE    -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long  -fno-common -pipe  -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -DNOKOGIRI_USE_PACKAGED_LIBRARIES -DNOKOGIRI_LIBXML2_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0"' -DNOKOGIRI_LIBXSLT_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26"' -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2  -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2  conftest.c  -L. -L/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libiconv/1.14/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/Users/ericcamalionte/.rvm/usr/lib -L.  -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libxml2/2.9.1/lib     -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2  -lxml2  -lruby.1.9.1-static  -lpthread -ldl -lobjc  "
sh: /usr/bin/gcc-4.2: No such file or directory
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */

To solve this problem I intalled apple-gcc42 using homebrew brew install apple-gcc42and created a symlink to my /usr/bin :

为了解决这个问题,我使用自制软件安装了 apple-gcc42brew install apple-gcc42并创建了一个指向我的 /usr/bin 的符号链接:

sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc-4.2

sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc-4.2

回答by thomas_witt

You can also install Nokogiri on Mac OS X 10.9 Maverickswith full XCode Install using:

您还可以使用完整的 XCode 安装在 Mac OS X 10.9 Mavericks上安装 Nokogiri :

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2

Update

更新

For those using Yosemitethe following command will work:

对于那些使用优胜美地的人,以下命令将起作用:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries

or, it might actually be in your MacOSX10.11.sdkfolder (mine was as of 18-Sep-2015) anyways, so even if you are not yet fully up to El Capitan, I had recently updated XCode and you may need to use the El Capitan SDK path, which follows next:

或者,它实际上可能在您的MacOSX10.11.sdk文件夹中(我的文件夹截至 2015 年 9 月 18 日),所以即使您还没有完全掌握 El Capitan,我最近更新了 XCode,您可能需要使用 El Capitan SDK路径,接下来是:

Update

更新

For those using El Capitanthe following command will work:

对于使用El Capitan的用户,以下命令将起作用:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries

Update

更新

For those using Sierrathe following command will work:

对于那些使用Sierra的人,以下命令将起作用:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries

回答by Micah Alcorn

After navigating the animated GIFs here, all that I had to do was simply xcode-select --installand the gem install nokogiriworked fine.

此处浏览动画 GIF 后,我所要做的就是简单xcode-select --install并且gem install nokogiri工作正常。

回答by Alpine

If you're running Xcode 5.1, the command line tools don't work for nokogiri 1.6.1. You'll need to download the Late october 2013 tools from Apple. Once you do that run

如果您运行的是 Xcode 5.1,则命令行工具不适用于 nokogiri 1.6.1。您需要从Apple下载 2013 年 10 月下旬的工具。一旦你这样做了

sudo xcode-select -s /Library/Developer/CommandLineTools/

to set up your machine to use the Xcode 5.0.X command line tools, then run

将您的机器设置为使用 Xcode 5.0.X 命令行工具,然后运行

gem install nokogiri

If you want to reset your command line tools to the Xcode.app version afterward run

如果您想在之后将命令行工具重置为 Xcode.app 版本,请运行

sudo xcode-select -r

Or, another thing you can do is add the flag to ignore unknown command line arguments. Then the install looks like this:

或者,您可以做的另一件事是添加标志以忽略未知的命令行参数。然后安装看起来像这样:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri

回答by ReneGAED

This is what worked for me on OSX Mavericks:

这就是在 OSX Mavericks 上对我有用的方法:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri -v '1.6.1' --verbose --no-ri --no-rdoc

回答by sulfurious

I'm on OSX Mavericks and my problem turned out to be a bad install of Ruby.

我在 OSX Mavericks 上,结果证明我的问题是 Ruby 安装不当。

So, I reinstalled ruby with rvm :

所以,我用 rvm 重新安装了 ruby​​ :

rvm remove ruby 2.0.0p451
rvm remove ruby-2.0.0-p451 && rvm install ruby-2.0.0-p451

I was then able to

我当时能够

gem install nokogiri --no-ri --no-rdoc

Problem solved.

问题解决了。

回答by King Spook

I like to stick with system-provided stuff typically. This worked for me:

我喜欢坚持使用系统提供的东西。这对我有用:

gem install nokogiri -- --with-iconv-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/ --with-iconv-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/

回答by philosodad

I ran into this problem immediately after installing the Mavericks 10.9.5 update and the 10.9 Developer tools update from Apple. I ran xcode-select --install, but that did not fix the problem. Then I opened XCode, accepted the eula, and quit XCode. That fixed the problem.

在安装了小牛队 10.9.5 更新和 Apple 的 10.9 开发者工具更新后,我立即遇到了这个问题。我跑了xcode-select --install,但这并没有解决问题。然后我打开了 XCode,接受了 eula,然后退出了 XCode。这解决了问题。

回答by edwardmp

This is the same as @thomas_witt's post but works on Mac OS X Sierra:

这与@thomas_witt 的帖子相同,但适用于 Mac OS X Sierra:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries

回答by Kingsley Ijomah

I had this problem today, on Maverick, this is how I ended up solving the issue:

我今天在 Maverick 上遇到了这个问题,这就是我最终解决问题的方式:

brew update
brew install libiconv
brew link libiconv

Make sure that you know the version of libiconv in Cellar mine below was 1.14, then install as below:

确保您知道下面 Cellar 我的 libiconv 版本是 1.14,然后安装如下:

gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14

If you require a particular version of nokogiri e.g -v '1.6.2.1' then install as:

如果您需要特定版本的 nokogiri 例如 -v '1.6.2.1' 然后安装为:

gem install nokogiri -v '1.6.2.1' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14

Nokogiri was installed successfully!

Nokogiri 安装成功!