Nokogiri构建本地扩展宝石失败(RuntimeError)?

4

我正在尝试使用以下命令安装Nokogiri:

sudo gem install nokogiri

这是安装后遇到的混乱:

Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
  ERROR: Failed to build gem native extension.

        /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin13.0.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /Users/micahsherman/.rvm/gems/ruby-1.9.3-p429/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin13.0.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... OK
Running 'compile' for libxslt 1.1.26... OK
Running 'install' for libxslt 1.1.26... OK
Activating libxslt 1.1.26 (from /Users/micahsherman/.rvm/gems/ruby-1.9.3-p429/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26)...
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/micahsherman/.rvm/rubies/ruby-1.9.3-p429/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/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:970:in `block in find_header'
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:254:in `open'
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:254:in `open'
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
  from /Users/micahsherman/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:969:in `find_header'
  from extconf.rb:166:in `<main>'


Gem files will remain installed in /Users/micahsherman/.rvm/gems/ruby-1.9.3-p429/gems/nokogiri-1.6.0 for inspection.
Results logged to /Users/micahsherman/.rvm/gems/ruby-1.9.3-p429/gems/nokogiri-1.6.0/ext/nokogiri/gem_make.out

我希望能得到一些提示或建议。我正在使用Ruby 1.9.4和Rails 3.2.13,但是我无法弄清楚为什么它不起作用。我正在使用Mavericks,我认为这可能是问题所在。

我已经更新了Xcode等工具。


1
你是从XCode组件还是命令行安装了XCode命令行工具? - Peter Goldstein
正如@PeterGoldstein所说,检查命令行工具是否已安装。 转到首选项|下载,并在组件下确保选择了命令行工具。 另外,我认为您不需要sudo。 - rainkinz
请检查mkmf.log文件以获取更多详细信息。那么你的mkmf.log有什么说法? - mu is too short
有大约13个mkmf.log文件。我应该寻找什么?此外,在XCode中,首选项/下载下,没有任何关于命令行工具的选项。 - m. sherman
我尝试运行常规的gem安装,但它回应“权限被拒绝”,然后我查看了nokogiri文档,上面写着要输入“sudo gem install nokogiri”。 - m. sherman
显示剩余2条评论
1个回答

2
这不是一个直接的解决方案,但是可以指导你朝正确的方向前进。 rvm 在解决自身问题方面非常可靠。按照以下步骤帮助 rvm 发挥其魔力:
运行 rvm requirements 查找缺失的内容。
使用 rvm pkg(在旧版的 rvm 上)或 rvm autolibs 安装缺失的软件包。
确保你在此过程中阅读了 rvm 要求你阅读的所有文档。
成功完成后,尝试安装 nokogiri

在使用rvm时遇到完全相同的问题。 - froderik
不一定要是“直接解决方案”。按照您的步骤解决了我的机器上类似的问题。一个可行的解决方案是最重要的事情。谢谢。 - Rafael Bugajewski

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