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

问题描述 投票:108回答:30

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

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

错误是:

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.

我从Homebrew安装了libxml2,libxslt和libiconv,并设置params来安装Nokogiri,但是也不行。

我无法在我的环境中找到什么问题,你能帮助我吗?

ruby macos nokogiri libxml2 osx-mavericks
30个回答
245
投票

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

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

Update

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

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

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

Update

对于使用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

对于使用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

3
投票

这与@ 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

2
投票

为了使安装起作用,我不得不修改gem install命令中的文件路径以匹配我系统上的文件路径。我有不同版本的libxml2和libiconv以及略有不同的文件结构。我的修改命令是:

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 
                        --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib 
                        --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28 
                        --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include 
                        --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib

2
投票

对于使用MacPorts的人,请确保您已通过libxml2安装了MacPorts。然后输入:

bundle config build.nokogiri --use-system-libraries
bundle install

这应该是诀窍,为我工作而不使用完整路径。


2
投票

如果您使用Homebrew,请使用brew install libxml2 libxslt


2
投票

这是另一个参考:

system: OS X Yosemite 10.10
rvm: 1.26.10
brew: 0.9.5
ruby: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]

我在安装nokogiri时遇到错误

像这样的错误:

.rvm/rubies/ruby-2.2.0-p0/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)

您必须先安装开发工具。

然后可能需要:

$ xcode-select --install

或者如果你有错误的话

checking for libxml/parser.h... no

我只是修复了lib路径:

gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 libxslt
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/

对于捆绑需要类似的东西:

bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
bundle install

2
投票

这适合我

system: OS X Yosemite 10.10
rvm: 1.26.10
ruby: ruby 2.2.1 

只需运行两个命令

$ xcode-select --install

它会要求你下载说“是”,然后它会要求安装xcode组件点击安装。

现在尝试使用以下命令安装gem

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

这对我来说适用于上述环境。


1
投票

我为Maverick遇到了同样的问题,解决方案是:

xcode-select --install

但是,这不起作用,因为Apple's download page for Command-line-tool现在没有公开提供该安装程序。

因此,如果您想拥有Mavricks的命令行工具,您需要拥有一个付费帐户。然后只有你能够安装它。安装后,您将不会遇到Nokogiri的这个问题。


1
投票

我在新的Mavericks安装上遇到了同样的错误。经过一段时间的判断后,我将我的Xcode应用程序包重命名为Xcode 5.0.1.app

显然,Nokogiri安装脚本没有引用它的路径,因此文件名中的空格引起了各种各样的麻烦。直到我尝试brew install libxml2,错误变得明显。

获得的经验:文件名中的空格是邪恶的。


1
投票

在我的情况下,我必须在符号链接后实际运行/usr/bin/gcc-4.2。您必须接受许可协议,否则它会挂起。


1
投票

错误消息在这里提供了一个线索:The compiler failed to generate an executable file. (RuntimeError)

xcode-select --install # not sure if this is required  
brew install apple-gcc42  
gem install nokogiri  

您还可能需要brew install并链接这些:

libxml2 libxslt

30
投票

在导航动画GIF here后,我所要做的只是xcode-select --installgem install nokogiri工作得很好。


1
投票
brew install libxml2 libxslt
gem install nokogiri -- \
    --with-xml2-include=/usr/local/Cellar/libxml2/*/include/libxml2 \
    --with-xml2-lib=/usr/local/Cellar/libxml2/*/lib \
    --with-xslt-dir=/usr/local/Cellar/libxslt/*

1
投票

对我来说,错误是gcc(4.2.1,从Homebrew安装)抱怨:

-E, -S, -save-temps and -M options are not allowed with multiple -arch flags

我通过强制x86_64解决了这个问题:

ARCHFLAGS="-arch x86_64" gem install nokogiri 

1
投票

升级到Maverick后,我遇到了类似的问题。我使用RVM和Ruby 1.9.2-p320,我尝试了几个解决方案,但没有解决问题。

然后我改为Ruby 2.1.2,bundle install立即安装了Nokogiri。


1
投票

如果有人在el capitan上遇到这个问题,那么使用捆绑器。

确保已安装xcode命令行工具并运行此命令:

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

1
投票

在尝试运行rails 3版本应用程序时,过去两周我遇到了同样的问题。

问题是你的rvm / rbenv没有使用C编译器。

对rvm使用此命令可以使用兼容的C编译器

CC=gcc rvm install-version

因此,如果您使用的是Ruby 1.9.3,请以这种方式使用它

CC=gcc rvm install-1.9.3

每次无法捆绑安装或任何东西时使用此命令。这个东西正在开发El Capitan,rails 3.2.16,ruby 1.9.3,mysql 5.7希望它能解决这个问题。

在尝试运行rails 3版本应用程序时,过去两周我遇到了同样的问题。

问题是你的rvm / rbenv没有使用C编译器。

对rvm使用此命令可以使用兼容的C编译器

CC=gcc rvm install-version

因此,如果您使用的是Ruby 1.9.3,请以这种方式使用它

CC=gcc rvm install-1.9.3

每次无法捆绑安装或任何东西时使用此命令。

这个东西正在开发El Capitan,rails 3.2.16,ruby 1.9.3,mysql 5.7希望它能解决这个问题。而且,如果您已经拥有Xcode,然后您也没有在安装任何gem时遇到相同的错误,请尝试此解决方案。


1
投票

在升级后不久我遇到同样的问题时,我在这里添加了我的发现:http://jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks/

修复只是这两个命令:

xcode-select --install
gem install nokogiri

希望能帮助到你。


0
投票

我也有这个问题。运行brew doctor表明我在/ user / local / lib中有一个意外版本的libiconv。

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
    /usr/local/lib/libcharset.1.dylib
    /usr/local/lib/libiconv.2.dylib

所以我删除了它们,并重新引用了libxml:

rm  /usr/local/lib/libiconv*
andromeda:nokogiri-1.6.0 Jeff$ brew install libxml2 libxslt
...
==> Summary
🍺  /usr/local/Cellar/libxslt/1.1.28: 145 files, 3.3M, built in 36 seconds

事实上,没有看到:

Jeff$ gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.0
1 gem installed

0
投票

这些答案都没有适用于我的特定情况,因为我是一个新手,我认为我的解决方案可能能够帮助其他人。

我正在使用Yosemite并使用Ruby 1.9.3p547。 p547存在安全隐患,因此我尝试更新到Ruby 1.9.3p550或更高版本。我使用RVM,然后尝试迁移我的宝石,其中许多没有去。然后我尝试捆绑安装但是失败了,我想也许这是各种路径和依赖关系之间的冲突所以我删除了旧版本的Ruby。这打破了一切。

我不断收到消息说C编译器丢失了,即使我已经下载了XCode并且最近更新了CLI工具。我发现另一个网站告诉我下载第三方GCC,我做了。这使一切变得更糟

现在我收到一条消息,说我需要修复我的配置文件和PATH,否则重新安装OSX可能会更容易。所以我做了。

无论如何,更长的故事只是很长:最终为我工作的解决方案是摆脱RVM并在运行bundle install之前使用brew来下载我想要的Ruby版本。安装正确版本的Nokogiri FIRST。

brew install ruby193
sudo gem install nokogiri -v '1.6.0'
bundle install

0
投票

对于Windows,您也可以尝试本地安装:

  1. 根据您的环境下载相应的gem。
  2. 转到保存gem文件的目录。
  3. gem install --local nokogiri-1.6.3.1-x86-mingw32.gem

如果没有工作,你可以检查你是否安装了zlib和mingw或正确的c编译器。


0
投票

这里的每一个单独的东西都不适合我(我没有进入brew重新安装,oy),但这终于做了(通过一些无关项目的错误报告找到):

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2

祝好运。是的#yakshaving!


20
投票

我找到了这个日志,发现找不到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 */

为了解决这个问题,我使用自制软件brew install apple-gcc42安装了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


-3
投票

检查命令行工具版本。设置您的机器以使用Xcode 5.0.X命令行工具,然后运行:

gem install nokogiri

15
投票

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

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

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

gem install nokogiri

如果要在以后运行时将命令行工具重置为Xcode.app版本

sudo xcode-select -r

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

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

12
投票

这对我在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

10
投票

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

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

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

我当时能够

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

问题解决了。


9
投票

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

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/

5
投票

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


3
投票

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

brew update
brew install libiconv
brew link libiconv

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

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

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

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

Nokogiri安装成功!

© www.soinside.com 2019 - 2024. All rights reserved.