ruby 在 OSX 10.10 Yosemite 上安装 Nokogiri
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24091869/
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
Installing Nokogiri on OSX 10.10 Yosemite
提问by gdavis
I recently upgrade to the 10.10 Yosemite beta, but I'm having trouble getting Nokogiri installed. I'm using RVM and Ruby 1.9.3. I've also followed the steps hereand tried following the instructions on Nokogiri's homepage.
我最近升级到 10.10 Yosemite 测试版,但在安装 Nokogiri 时遇到了问题。我正在使用 RVM 和 Ruby 1.9.3。我也按照这里的步骤操作,并尝试按照 Nokogiri 主页上的说明操作。
I've installed libxml2 (2.9.1) and libxslt (1.1.28) via homebrew, and have tried using the command line tools from both my Xcode 5 install and Xcode 6 beta.
我已经通过自制软件安装了 libxml2 (2.9.1) 和 libxslt (1.1.28),并尝试使用 Xcode 5 install 和 Xcode 6 beta 中的命令行工具。
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>'
Anyone have an idea on how to fix these install errors?
任何人都知道如何修复这些安装错误?
EDIT 6/10/14:After trying for a couple days to get Nokogiri installed on OSX 10.10, I ended up abandoning the task and restored 10.9 on my machine. Several libraries and bundles need to be updated in order to work in the 10.10 environment.
2014 年 6 月 10日编辑:在尝试在 OSX 10.10 上安装 Nokogiri 几天后,我最终放弃了该任务并在我的机器上恢复了 10.9。几个库和包需要更新才能在 10.10 环境中工作。
回答by activars
I managed to install Nokogiri under Yosemite (OS X 10.10 Preview).
我设法在优胜美地(OS X 10.10 预览版)下安装了 Nokogiri。
Step 1: Install Brew
第 1 步:安装 Brew
Skip this if brew was installed.
如果安装了 brew,请跳过此步骤。
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step 2: Install brew libs
第 2 步:安装 brew 库
brew tap homebrew/dupes
brew install libxml2 libxslt
brew install libiconv
Step 3: Download and install Apple Commandline Tools for 10.10
第 3 步:下载并安装适用于 10.10 的 Apple 命令行工具
It's important that you need to restart after installation.
安装后需要重新启动,这一点很重要。
Link: command_line_tools_for_osx_10_10_june_2014.dmg
链接:command_line_tools_for_osx_10_10_june_2014.dmg
After restarted, you can check installation in Terminal:
重新启动后,您可以在终端中检查安装:
> xcode-select --install
-> xcode-select: error: command line tools are already installed, use "Software Update" to install updates
This error means you have commandline tool installed correctly.
此错误意味着您已正确安装命令行工具。
Installing Nokogiri
安装 Nokogiri
Try using n previous version 1.6.1 in your Gemfile, version 1.6.2.1 has issues currently with "10.10 Preview". It only works with my rbenv Ruby 2.0.0p247, failed to install on 2.1.1. You can give your existing Ruby versions a couple of tries.
尝试在您的 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/
回答by xrage
libxml2 - 1.6.6.2 in Yosemite:
libxml2 - 优胜美地中的 1.6.6.2:
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
回答by Maximus S
For Mac OS El Capitan:
对于 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
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
回答by Tom Coleman
This worked for me:
这对我有用:
ARCHFLAGS="-arch x86_64" gem install nokogiri -v '1.6.0'
回答by edx
I had the same problem with MacPorts ruby2.1:
我在 MacPorts ruby2.1 上遇到了同样的问题:
can not gem install nokogiri on osx10.10 with macports ruby2.1
The install starts, the cpu goes to 50% on a single core at 100%, then CPU drops to near zero, but iostat tpsgoes through the wall.
安装开始,单核上的 CPU 以 100% 的速度运行到 50%,然后 CPU 下降到接近于零,但iostat tps会穿墙。
This helped:
这有助于:
# 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
回答by Manas Tungare
This finally worked for me:
这最终对我有用:
sudo gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
回答by ramijames
For anyone else that hasn't been able to get this to work on El Capitan, what finally worked for me was:
对于无法在 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
I don't have macports installed, and my system is a weird hodge-podge. Forcing specific installations for each dependency is the only way that I can get Nokogiri to compile. Super annoying, but at least it works.
我没有安装 macports,我的系统是一个奇怪的大杂烩。强制为每个依赖项进行特定安装是我让 Nokogiri 编译的唯一方法。超级烦人,但至少它有效。
回答by IM_AG
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
回答by Daniel Romero
The instructions from the Nokogiri websiteworked for me on both OSX 10.9 and 10.10.
从这些指令引入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
回答by parquar
(full answer here https://gist.github.com/chrisb/4d6a09c6cc1ca2e1b14e)
(完整答案在这里https://gist.github.com/chrisb/4d6a09c6cc1ca2e1b14e)
It looks like Homebrew somehow depends on Ruby being in Versions/1.8 (though even Mavericks ships with 2.0). Until Homebrew addresses this, we'll symlink our system version of Ruby to the one Homebrew looks for.
看起来 Homebrew 以某种方式依赖于 Ruby 版本/1.8(尽管即使是 Mavericks 也附带 2.0)。在 Homebrew 解决这个问题之前,我们会将系统版本的 Ruby 符号链接到 Homebrew 寻找的版本。
Create the folder:
创建文件夹:
sudo mkdir -p /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
Then symlink the binary:
然后符号链接二进制文件:
sudo ln -s /usr/bin/ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

