【问题标题】:Issue installing the Nokogiri gem in Mac OS X 10.5.8在 Mac OS X 10.5.8 中安装 Nokogiri gem 时出现问题
【发布时间】:2012-03-08 10:18:05
【问题描述】:

我正在尝试在 OS X Leopard (10.5.8) 中的 RVM 管理的 Ruby 1.8.7 安装下安装 Nokogiri gem。

我收到以下错误:

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

        /Users/user/.rvm/rubies/ruby-1.8.7-p352/bin/ruby extconf.rb
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... yes
checking for xsltParseStylesheetDoc() in -lxslt... yes
checking for exsltFuncRegister() in -lexslt... yes
checking for xmlHasFeature()... no
-----
The function 'xmlHasFeature' is missing from your installation of libxml2.  Likely this means that your installed version of libxml2 is old enough that nokogiri will not work well.  To get around this problem, please upgrade your installation of libxml2.

Please visit http://nokogiri.org/tutorials/installing_nokogiri.html for more help!
*** extconf.rb failed ***

我通过 homebrew (brew install libxml2) 安装了最新的 libxml2,所以我不知道还能尝试什么。


更新

我尝试了 Nokogiri 网站上的说明,但无法让 Nokogiri gem 安装识别 libxml2。

根据the instructions 我通过自制软件安装并链接了 libxml2 和 libxslt:

brew install libxml2 libxslt
brew link libxml2 libxslt
gem install nokogiri

错误信息已更改,但Nokogiri安装抱怨缺少libxml2:

...
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

安装的libxml2版本是2.7.8。


更新更新:

我尝试从 homebrew 安装 iconv 库,看看是否可以解决错误checking for iconv_open() in iconv.h... no,所以我运行了命令:

brew install libiconv
brew link libiconv

完成安装后,我尝试再次安装 nokogiri gem,以获取此错误消息,安装程序现在抱怨 libiconv 丢失

hecking 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... no
-----
libiconv is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----

我一无所知。

【问题讨论】:

    标签: ruby rubygems rvm nokogiri osx-leopard


    【解决方案1】:

    根据您需要使用的http://nokogiri.org/tutorials/installing_nokogiri.html 处的说明:

    brew install libxml2 libxslt
    brew link libxml2 libxslt
    

    然后

    gem install nokogiri
    

    你是用这些还是只用brew install libxml2

    【讨论】:

    • 谢谢你,我不敢相信我错过了官方 nokogiri 页面上的此类文章。我想我在其他平台(甚至 OS X 10.6+)上安装 nokogiri 没有任何问题,所以我从来不需要它。我只安装了软件包,但没有链接它们;我会试试这个解决方案,然后告诉你会发生什么。
    • 我添加了一个更新,按照网站上的说明,我仍然无法安装它
    • 最后我更新了 OS X 版本并通过标准方式让一切正常工作。
    【解决方案2】:

    确保没有可用的 Nokogiri 版本:

    use gem uninstall nokogiri
    

    首先安装 Xcode 的命令行工具。参考“How to use/install gcc on Mac OS X 10.8 / Xcode 4.4”。

    然后运行以下命令:

    brew install libxml2
    gem install nokogiri
    

    现在效果很好,我试过了。

    【讨论】:

      【解决方案3】:
      brew install libxml2 libxslt
      gem install nokogiri -- \
          --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.x/lib \
          --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.xx \
          --with-iconv-lib=/usr/lib \
          --with-iconv-include=/usr/local/include
      

      【讨论】:

      • 请在您提供的代码片段中添加一些描述,以便您的回答更有意义。
      猜你喜欢
      • 2015-03-19
      • 2012-02-04
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      相关资源
      最近更新 更多