无法在 Mac 上安装 Ruby gem libxslt-ruby,因为它找不到 libxml2

Posted

技术标签:

【中文标题】无法在 Mac 上安装 Ruby gem libxslt-ruby,因为它找不到 libxml2【英文标题】:Cannot install Ruby gem libxslt-ruby on Mac cause it does not find libxml2 【发布时间】:2014-05-11 00:17:33 【问题描述】:

我已经通过 Brew 在我的 Mac 上安装了 libxml2 和 libxslt,但是

gem install libxslt-ruby -- --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xml2- include=/usr/local/opt/libxml2/include --with-xslt-include=/usr/local/opt/libxslt/include --version=1.1.1

gem install libxslt-ruby -- --with-xml2-dir=/usr/local/Cellar/libxml2/2.9.1 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1 /lib --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --version=1.1.1

抛出

    Building native extensions.  This could take a while...
    /Users/gawlim/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir /usr/local/Cellar in PATH, mode 040777
    ERROR:  Error installing libxslt-ruby:
        ERROR: Failed to build gem native extension.

            /Users/gawlim/.rbenv/versions/1.9.3-p484/bin/ruby extconf.rb --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xml2-include=/usr/local/opt/libxml2/include --with-xslt-include=/usr/local/opt/libxslt/include -v 1.0.8
    checking for ruby/io.h... yes
    checking for inflate() in -lz... yes
    checking for iconv_open() in -liconv... yes
    checking for xmlXPtrNewRange() in -lxml2... yes
    checking for libxml/xmlversion.h... no
    checking for libxml/xmlversion.h in /opt/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
    *** 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=/Users/gawlim/.rbenv/versions/1.9.3-p484/bin/ruby
        --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-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
        --with-xml2-include=$xml2-dir/include
        --with-xml2-lib=$xml2-dir/lib
        --with-xslt-dir
        --without-xslt-dir
        --with-xslt-include=$xslt-dir/include
        --with-xslt-lib
        --without-xslt-lib=$xslt-dir/lib
        --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-zlib
        --without-zlib
        --with-iconvlib
        --without-iconvlib
        --with-xml2lib
        --without-xml2lib
     extconf failure: %s
    need libxml2.

    Install the library or try one of the following options to extconf.rb:

    --with-xml2-dir=/path/to/libxml2
    --with-xml2-lib=/path/to/libxml2/lib
    --with-xml2-include=/path/to/libxml2/include

【问题讨论】:

【参考方案1】:

虽然是一个老问题,但我会分享我找到的解决方案。在安装 libxslt-ruby gem 之前,运行以下命令:

gem update --system

这是该命令的文档:

http://guides.rubygems.org/command-reference/#gem-update

【讨论】:

以上是关于无法在 Mac 上安装 Ruby gem libxslt-ruby,因为它找不到 libxml2的主要内容,如果未能解决你的问题,请参考以下文章

ruby nokogiri gem install mac osx high sierra

Mac中gem安装与移除

使用新的 Ruby 版本在 Mac OSX 上安装 gem

无法使用 Mavericks 在我的 Mac 上安装 PG gem

Bundle 无法在 Mac OSX 10.7 上安装 RMagick gem

Ruby gem rmagick 不会安装在 Mac OS X 上