为什么在Mac OS上安装Nokogiri失败,libiconv丢失?

我一直试图在Mac OS 10.9.3上安装Nokogiri,无论我尝试什么,安装都会失败,并显示以下错误消息:

$ sudo 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
Building native extensions with: '--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'
This could take a while...
Building nokogiri using packaged libraries.
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/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
Building nokogiri using packaged libraries.
checking for iconv.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
checking for libiconv_open() in iconv.h... no
checking for libiconv_open() in -liconv... no
-----
libiconv 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
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build


Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.2.1/ext/nokogiri/gem_make.out

在网络上发现很多帮助后,包括使用brew构建和安装libxml2和libxslt以及从源代码构建libiconv(如“安装Nokogiri”中所述),错误依然存在。

当试图运行Nokogiri的安装时,libxml2和libxslt似乎很好,但不是libiconv。

更了解这些事情的人知道如何安装Nokogiri?


我遇到过同样的问题。 不幸的是,“安装Nokogiri”不包括Iconv问题。 以下是我解决问题的方法。

首先安装自制软件,它会让你的生活更轻松。 如果您已经安装了它,请确保通过如下更新获取最新公式:

brew update

注意 :在OSX 10.9+中,您可能需要安装xCode命令工具才能安装libiconv。

xcode-select --install

然后安装更新版本的libiconv

brew install libiconv

然后链接你的新iconv库:

brew link libiconv

然后安装你的宝石

gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14

尝试使用系统库。 OSX自带更新版本的libiconv,但默认安装脚本似乎有问题

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

编辑:如果使用捆绑器,正如Geoff所说,你可以这样做:

bundle config build.nokogiri --use-system-libraries

@ Cory的解决方案包含正确的答案,但小牛的解决方案实际上比顶级解决方案简单得多,所以我只需要进行必要的步骤重新发布。

在小牛队(OSX 10.9+)上:

安装Xcode命令行工具:

xcode-select --install

然后安装你的宝石:

gem install nokogiri
链接地址: http://www.djcxy.com/p/61047.html

上一篇: Why does installing Nokogiri on Mac OS fail with libiconv is missing?

下一篇: axis with labels in months