Nokogiri为什么不安装?

时间:2013-07-28 23:43:02

标签: ruby nokogiri

我在安装Nokogiri时遇到了麻烦。当我运行bundle installgem install nokogiri时,安装失败。

我得到的错误是: (注意:此故障来自使用nokogiri.org上的安装命令)

Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /Users/roneesh/.rbenv/versions/1.9.3-p194/bin/ruby extconf.rb --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.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
Extracting libxml2-2.8.0.tar.gz into tmp//ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... ERROR, review 'tmp//ports/libxml2/2.8.0/configure.log' to see what happened.
*** 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.

我正在尝试使用的命令是:

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.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

我已经用brew安装了xml2,xslt和libiconv,并在上面输入了正确的版本。仍然没有决议。我没有做过的唯一事情就是来自source的libiconv(我的wget命令由于某种原因无效)。

2 个答案:

答案 0 :(得分:5)

您需要指定nokogiri来代替使用系统库,因此它不会尝试自己构建它们。

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install

在此处找到答案:Error installing nokogiri 1.6.0 on mac (libxml2)

答案 1 :(得分:1)

设置NOKOGIRI_USE_SYSTEM_LIBRARIES=1也为我做了诀窍,但我必须首先安装gem依赖的本机库(我用Homebrew做了),然后告诉gem使用它们。

汇总:

  • 如果以前安装过,请卸载gem:
    $ gem uninstall nokogiri

  • 使用Homebrew安装libxml2libxsltlibiconv
    $ brew install libxml2 libxslt libiconv

  • 安装gem,指定要链接的库的路径:
    $ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

相关问题