Ruby-on-rails 无法安装 Nokogiri gem
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27496498/
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
Failing to install Nokogiri gem
提问by Katie H
I'm working on a rails app that allows for image attachments to each use account. I'm using paperclip and amazon web services:
我正在开发一个 Rails 应用程序,该应用程序允许为每个用户帐户添加图像附件。我正在使用回形针和亚马逊网络服务:
gem 'paperclip'
gem 'aws-sdk'
When I run bundle install, I get this message:
当我运行 bundle install 时,我收到以下消息:
extconf failed, exit code 1
extconf 失败,退出代码 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out
An error occurred while installing nokogiri (1.6.5), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.5'` succeeds before bundling.
When I try running 'gem install nokogiri', I get this message:
当我尝试运行“gem install nokogiri”时,我收到以下消息:
extconf failed, exit code 1
extconf 失败,退出代码 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out
My OS is Mac OS X 10.9.4 Mavericks. What's going on here? How can I get nokogiri to install and behave properly?
我的操作系统是 Mac OS X 10.9.4 Mavericks。这里发生了什么?如何让 nokogiri 安装并正常运行?
Full stack trace:
完整堆栈跟踪:
Building native extensions with: '--use-system-libraries'
This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... yes
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** 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
--without-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=/usr/local/rvm/rubies/ruby-2.1.2/bin/ruby
--help
--clean
--use-system-libraries
--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-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-pkg-config
--without-pkg-config
--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-exslt-dir
--without-exslt-dir
--with-exslt-include
--without-exslt-include=${exslt-dir}/include
--with-exslt-lib
--without-exslt-lib=${exslt-dir}/lib
--with-libexslt-config
--without-libexslt-config
extconf failed, exit code 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out
回答by Katie H
This works like a charm!
这就像一个魅力!
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
回答by kasperite
Have you tried gem install nokogiri -v 1.6.5 -- --use-system-libraries?Most nokogiri errors are to do with libxml2, libxslt or libiconv config.
您尝试过gem install nokogiri -v 1.6.5 -- --use-system-libraries吗?大多数 nokogiri 错误与 libxml2、libxslt 或 libiconv 配置有关。
Nokogiri docsshould give you more instructions. If the solution doesn't work, you may want to post full stack trace so others can help more.
Nokogiri文档应该给你更多的说明。如果解决方案不起作用,您可能需要发布完整的堆栈跟踪,以便其他人可以提供更多帮助。
回答by kenorb
On Ubuntu, try installing the following dependencies:
在 Ubuntu 上,尝试安装以下依赖项:
sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev
回答by equivalent8
after upgrading to Rails 4.2.4 (which inculdes Nokogiri 1.6.6.2) on Ubuntu 14.04 (I'm using RVM) I needed to do this:
1.6.6.2在 Ubuntu 14.04(我使用 RVM)上升级到 Rails 4.2.4(包括 Nokogiri )后,我需要这样做:
sudo apt-get install libgmp-dev
or
或者
sudo apt-get install libgmp3-dev
回答by Chandru
As per the nokogiri installation instruction installing,
根据 nokogiri 安装说明安装,
sudo apt-get install zlib1g-dev
sudo apt-get install zlib1g-dev
solved the issue for me.
为我解决了这个问题。
回答by Patru
Since the OP was referencing bundle installwhich I happened to use as well I think it is worth pointing out the Installing Nokogiripage which eventually revealed the most elegant solution (which worked for me also on Mac OS X 10.8.5):
由于 OP 正在引用bundle install我碰巧使用的内容,因此我认为值得指出安装 Nokogiri页面,该页面最终揭示了最优雅的解决方案(在 Mac OS X 10.8.5 上也对我有用):
bundle config build.nokogiri --use-system-libraries
bundle install
This instructs bundler to install nokogiri as in the answers of @kasperite
这指示捆绑程序安装 nokogiri,如@kasperite 的答案
回答by Alexander Luna
I solved this by installing the xcode dependencies that Nokogiri needs to be installed:
我通过安装 Nokogiri 需要安装的 xcode 依赖项解决了这个问题:
xcode-select --install
After that run bundle install again and it should work.
之后再次运行 bundle install ,它应该可以工作。
回答by beckah
To take from dylanjhunt's awesome answer on Github, just in case anyone hasn't tried it,
从dylanjhunt 在 Github 上的精彩回答中获取,以防万一有人还没有尝试过,
Just to add to this, I was having a very similar issue that was resolved by updating dev tools.
xcode-select --installHoping someone sees this that had not tried doing this yet and it helps.
补充一点,我遇到了一个非常相似的问题,该问题已通过更新开发工具解决。
xcode-select --install希望有人看到这个还没有尝试过这样做,它会有所帮助。
回答by Tamer
回答by Wildcard
I didn't get the same error message as you, but I wanted to note what I finally found as the extraordinarily simple solutionfor installing nokogiri on Ubuntu:
我没有收到与您相同的错误消息,但我想注意我最终发现的在 Ubuntu 上安装 nokogiri的非常简单的解决方案:
Turns out the nokogiri build process depends on patch.
结果证明 nokogiri 构建过程依赖于patch.
Run: sudo apt-get install patch
跑: sudo apt-get install patch
I was working on a VM (a vagrant box, actually), which is why I didn't already have patchinstalled.
我正在开发一个虚拟机(实际上是一个流浪盒),这就是我还没有patch安装的原因。
The error I got (after a lot of other stuff that looked like an error but was actually just a warning) was:
我得到的错误(在许多其他看起来像错误但实际上只是警告的东西之后)是:
Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-pc-linux-gnu/ports/libxml2/2.9.2... OK
Running patch with /var/lib/gems/1.9.1/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch...
Running 'patch' for libxml2 2.9.2... ERROR, review '/var/lib/gems/1.9.1/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-pc-linux-gnu/ports/libxml2/2.9.2/patch.log' to see what happened.
I've deleted the log by now (the above was in my terminal session), but the patch.logfile referenced above was absurdly simple; it just said something like patch not found.
我现在已经删除了日志(上面是在我的终端会话中),但是patch.log上面引用的文件非常简单;它只是说了类似的话patch not found。
Boy did I feel silly for all the digging around I did installing libraries trying to fix it! :)
天啊,我是否为我安装库试图修复它所做的所有挖掘而感到愚蠢!:)

