新手问题 gem install nokogiri 失败: Error installing nokogiri

zicjin · 2014年05月03日 · 最后由 afeiship 回复于 2019年09月26日 · 15766 次阅读

在项目依赖 capybara 时需要 nokogiri。安装过 libxml2 libxslt,也重装过 ruby。不知道怎么办了。

cheneytekimbp:rails_projects zicjin$ sudo gem install nokogiri
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin13.1.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin13.1.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin13.1.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... OK
Running 'compile' for libxslt 1.1.26... OK
Running 'install' for libxslt 1.1.26... OK
Activating libxslt 1.1.26 (from /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin13.1.0/libxslt/1.1.26)...
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for xmlParseDoc() in -lxml2... no
-----
libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/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
    --with-iconvlib
    --without-iconvlib
    --with-xml2lib
    --without-xml2lib

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-13/2.0.0/nokogiri-1.6.1/gem_make.out
sudo apt-get install libxslt-dev libxml2-dev

#1 楼 @Rei 我是 mac brew install libxslt-dev libxml2-dev Error: No available formula for libxslt-dev

3 楼 已删除

#2 楼 @zicjin 错误提示你去看看 http://nokogiri.org/tutorials/installing_nokogiri.html 里面在 Mac OSX 一节有关于如何安装的介绍。

#2 楼 @zicjin

Mac 应该用:

$ brew install libxml2 libxslt

#5 楼 @huacnlee 都安装了,包括 libiconv,是需要什么命令做一个激活么~~

sudo gem uninstall nokogiri

全选,Y 确认卸载

sudo gem install nokogiri -- --use-system-libraries

我也遇到了这个问题,后代找到解决方案了么

@runup v1.6.8 has build problems, try following the issue: https://github.com/sparklemotion/nokogiri/issues/1483 若是本地 development 开发几台的话可以试试: brew uninstall xz; gem install nokogirl -v 1.6.8

#10 楼 @twairball 具体运行什么命令?

我也刚遇到 比较坑

huacnlee [该话题已被删除] 提及了此话题。 07月27日 16:51

2 年了还是这么坑.. 😑

huacnlee 安装 Rails 失败,多次尝试未果 提及了此话题。 11月30日 10:22

你们解决这个问题了吗? 怎么感觉还在...

需要 登录 后方可回复, 如果你还没有账号请 注册新账号