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

我把我的OSX(Lion)升级到小牛,我不能为我的项目安装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,并设置了参数来安装Nokogiri,但是不能工作。

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

您也可以在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 

更新

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

 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 SDKpath:

更新

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

更新

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

在浏览GIFanimation之后,我所要做的只是简单xcode-select --installgem install nokogiri

我发现这个日志,看到没有findgcc-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 */ 

为了解决这个问题,我使用homebrew brew install apple-gcc42brew install apple-gcc42并创build了一个符号链接到我的/ usr / bin:

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

如果您正在运行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 

这是OSX小牛对我的工作原理:

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

我在OSX小牛,我的问题原来是一个糟糕的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 

问题解决了。

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

 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/ 

从Apple安装Mavericks 10.9.5更新和10.9开发人员工具更新后,我立即遇到了这个问题。 我运行xcode-select --install ,但是没有解决问题。 然后我打开XCode,接受eula,退出XCode。 这解决了这个问题。

今天我遇到了这个问题,在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 eg -v'1.6.2.1',那么安装如下:

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

Nokogiri安装成功!

这与@ thomas_witt的post是一样的,但是可以在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 

要使安装正常工作,我必须修改gem install命令中的文件path以匹配我的系统上的文件path。 我有不同版本的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 

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

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

这应该做的伎俩,为我工作,而不使用完整的path。

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

这里是另一个参考:

 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 

我只是通过以下方式修复libpath:

 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 

这对我有用

 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 

这对于我以上的环境工作。

我遇到了同样的问题Mavrick,解决scheme是:

 xcode-select --install 

但是,这不工作,因为苹果公司的下载页面的命令行工具没有现在公开提供的安装程序。

所以,如果你想拥有Mavricks的命令行工具,你需要有一个付费账户 。 那么只有你将能够安装它。 一旦你安装它,你不会面对Nokogiri这个问题。

我有一个新鲜的小牛安装这个相同的错误。 经过一段时间的判断后,我将Xcode应用程序包重命名为Xcode 5.0.1.app

显然Nokogiri的安装脚本并没有引用它的path,所以文件名中的空格导致了各种各样的麻烦。 直到我尝试brew install libxml2的错误变得明显。

获得的教训:文件名中的空格是邪恶的。

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

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

希望能帮助到你。

错误消息给出了一个线索: The compiler failed to generate an executable file. (RuntimeError) 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安装并链接这些:

 libxml2 libxslt 
 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/* 

对我来说,错误的是,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 

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

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

如果任何人在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 

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

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

使用此命令rvm采取兼容的C编译器

 CC=gcc rvm install-version 

所以,如果你使用的是Ruby 1.9.3,就用这种方法

 CC=gcc rvm install-1.9.3 

每次你无法捆绑安装或任何东西时使用这个命令。 这个东西是工作在埃尔卡皮坦,铁轨3.2.16,ruby1.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 

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

这个东西是工作在埃尔卡皮坦,铁轨3.2.16,ruby1.9.3,MySQL 5.7希望,这将解决这个问题。 而且,如果你已经有Xcode,然后你也没有得到同样的错误安装任何gem,试试这个解决scheme。

我也有这个问题。 运行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 

所以我删除了他们,并rebrewed 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 

最后,我安装了nokogiri:

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

这些答案都没有为我的具体情况工作,因为我是一个新手,我想我的解决scheme可能能够帮助别人。

我正在使用优胜美地,并使用Ruby 1.9.3p547。 p547有安全风险,所以我试图更新到Ruby 1.9.3p550或更高版本。 我使用RVM,然后试图迁移我的gem,其中许多人没有去。 然后我尝试捆绑安装,但那是失败的,我想也许这是各种path和依赖关系之间的冲突,所以我删除了旧版本的Ruby。 这打破了一切。

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

现在我收到一条消息,说我需要修复我的configuration文件和path,或者重新安装OSX可能会更容易。 所以我做了。

无论如何,更长的故事只是漫长而已:最终解决scheme是摆脱RVM,然后在运行bundle install之前使用brew下载我想要的Ruby版本。 安装正确版本的Nokogiri FIRST。

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

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

  1. 根据您的环境下载适当的gem。

  2. 转到您保存gem文件的目录。

  3. gem install --local nokogiri-1.6.3.1-x86-mingw32.gem

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

这里的每一件事都没有为我做(我没有进入brew重新安装,哦),但最终这样做(通过一个无关项目的错误报告):

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

祝你好运。 是的#yakshaving!

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

 gem install nokogiri