我最近升级到10.10 Yosemite测试版,但是我在安装Nokogiri时遇到了麻烦。我使用RVM和Ruby 1.9.3。我也遵循了这里的步骤,并尝试遵循Nokogiri主页上的说明。
我已经安装了libxml2(2.9.1)和libxslt(1.1.28)通过自制,并尝试使用命令行工具从我的Xcode 5安装和Xcode 6测试版。
gem install nokogiri -v '1.5.5'
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/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/grantdavis/.rvm/rubies/ruby-1.9.3-p362/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/grantdavis/.rvm/rubies/ruby-1.9.3-p362/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/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:970:in `block in find_header'
from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:969:in `find_header'
from extconf.rb:114:in `<main>'
有人知道如何修复这些安装错误吗?
编辑6/10/14:在尝试了几天将Nokogiri安装在OSX 10.10上之后,我最终放弃了这个任务并在我的机器上恢复了10.9。为了在10.10环境中工作,需要更新几个库和包。
我成功地在Yosemite (OS X 10.10 Preview)下安装了Nokogiri。
步骤1:安装Brew如果安装了brew,请跳过此操作。
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
步骤2:安装brew库brew tap homebrew/dupes
brew install libxml2 libxslt
brew install libiconv
步骤3:下载并安装Apple Commandline Tools for 10.10
安装后需要重新启动是很重要的。
链接:command_line_tools_for_osx_10_10_june_2014.dmg
重新启动后,您可以在Terminal中检查安装:
> xcode-select --install
-> xcode-select: error: command line tools are already installed, use "Software Update" to install updates
此错误表示您已正确安装命令行工具。
安装Nokogiri尝试在Gemfile中使用以前的1.6.1版本,1.6.2.1版本目前在"10.10预览版"中存在问题。它只适用于我的rbenv Ruby 2.0.0p247,在2.1.1上安装失败。你可以尝试一下现有的Ruby版本。
gem install nokogiri -v '1.6.1' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/
libxml2 - 1.6.6.2 in Yosemite:
sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -- --use-system-libraries -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-xslt-lib=/usr/local/lib --with-xslt-include=/usr/local/include
Mac OS El Capitan:
gem install nokogiri -v '1.6.7.1' -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2
这工作对我来说:
ARCHFLAGS="-arch x86_64" gem install nokogiri -v '1.6.0'
我有同样的问题与MacPorts ruby2.1:
can not gem install nokogiri on osx10.10 with macports ruby2.1
安装开始,cpu在单核上达到100%时达到50%,然后cpu下降到接近零,但是iostat tps
穿过墙。
这帮助:
# port install libiconv libxslt libxml2
# gem install nokogiri -- --use-system-libraries --with-iconv-dir=/opt/local --with-xml2-dir=/opt/local --with-xslt-dir=/opt/local
这终于为我工作了:
sudo gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
对于那些无法在El Capitan上工作的人来说,最终为我工作的是:
sudo gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-iconv-dir=/usr/local/opt/libiconv --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 --with-xslt-config=/usr/local/opt/libxslt/bin/xslt-config
我没有安装macports,我的系统是一个奇怪的大杂烩。强制每个依赖项的特定安装是我能够编译Nokogiri的唯一方法。超级烦人,但至少管用。
Nokogiri网站上的说明对我在OSX 10.9和10.10上都有效。
brew unlink gcc-4.2 # you might not need this step
gem uninstall nokogiri
xcode-select --install
gem install nokogiri
sudo gem update --system
sudo gem install nokogiri -v '1.6.6.2' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib
(完整答案在此https://gist.github.com/chrisb/4d6a09c6cc1ca2e1b14e)
看起来Homebrew在某种程度上依赖于Ruby的版本/1.8(尽管Mavericks的版本是2.0)。在Homebrew解决这个问题之前,我们将把我们的系统版本的Ruby符号链接到Homebrew查找的版本。
创建文件夹:
sudo mkdir -p /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
然后符号链接二进制文件:
sudo ln -s /usr/bin/ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
这对我有用:
$ brew install libxml2 libxslt # optional?
$ brew install libiconv # optional?
$ gem install nokogiri -v 1.6.8 -- --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2
在这样的环境下:
$ sw_vers -productVersion
10.9.4
$ brew -v
Homebrew 0.9.9 (git revision aa747; last commit 2016-05-26)
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14
- RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [universal.x86_64-darwin13]
唯一有效的方法是将编译器从apple-gcc42升级到gcc48:
brew uninstall apple-gcc42
brew install gcc48 # this might take an hour or so
rvm implode
curl -sSL https://get.rvm.io | bash -s stable # reinstall RVM
rvm install ruby-1.9.3-p551
bundle update libv8 # 3.16.14.3 doesn't work but 3.16.14.7 does
bundle
如果你使用的是OS X 10.10和MacPorts,你必须安装pkgconfig:
sudo port install pkgconfig libxml2 libxslt libiconv
如果你想自动使用MacPorts库而不添加配置选项,你需要将它添加到你的.profile或.bashrc:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
export LDFLAGS="-L/opt/local/lib"
export CPPFLAGS="-I/opt/local/include"
你也可以添加这个来告诉Nokogiri总是使用你的系统库:
export NOKOGIRI_USE_SYSTEM_LIBRARIES=Y
添加所有这些导出后重新启动终端。
使用这个配置你可以安装Nokogiri:
gem install nokogiri
我在OS X Yosemite版本10.10.5上得到同样的错误信息
我最近做了各种操作系统更新,结果发现我只需要使用以下命令接受新的xcode许可协议:
sudo xcodebuild -license
在我的例子中,错误消息写在下面,相应的解决方案也是
错误信息:
...
libxml2 is missing. Please locate mkmf.log to investigate how it is failing.
...
解决方案:
gem install nokogiri -- --use-system-libraries --with-libxml2lib=/usr/local/opt/libxml2/lib/libxml2.a
我直接给了它libxml2库的路径。a
安装完整的Xcode对于老版本的Nokogiri来说,这是唯一对我有效的方法。
对于我来说,切换到Xcode 5而不是使用Xcode 6的CLI工具:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
我认为这个问题与没有找到系统Ruby或安装了多个Ruby有关。
- 您是否使用RVM来管理红宝石?
-
ruby -v
的输出是多少?
这些应该是寻找解决方案的起点。
bad interpreter
错误与Ruby安装的问题有关。
理想情况下,您应该从系统Ruby开始,即Xcode附带的Ruby。所以,你可以完全卸载Xcode使用:
http://osxdaily.com/2012/02/20/uninstall-xcode/卸载brew
、rvm
并重新安装。
试试:
xcode-select --install
这个成功了:
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
源代码
解决Mac OS x上"安装Mac OS El Capitan时无法写入/usr/bin/nokogiri "问题:
sudo gem install nokogiri -n /usr/local/bin
参考:https://www.bountysource.com/issues/28085261-can-t-write-usr-bin-nokogiri-while-installing-on-mac-os-ei-capitan
试试这个:
按照指定的顺序安装这些包:
brew install libxml2 libxslt
brew link libxml2 libxslt
gem install nokogiri
尝试更新gcc版本:
- 在OSX上更新GCC
- https://superuser.com/questions/517218/how-do-i-install-gcc-4-7-2-on-os-x-10-8
- 在OS X 10.9上安装libv8 gem +
- libv8 (3.11.8.17) bundle install error for Mac