Why does installing Nokogiri on Mac OS fail with l

2020-01-23 13:25发布

I've been trying to install Nokogiri on Mac OS 10.9.3 and whatever I try, the install fails in the end with the following error message:

$ 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

After following a lot of help found around the web including building and installing libxml2 and libxslt using brew and building libiconv from the sources (as described in "Installing Nokogiri"), the error remains the same.

When trying to run the installation for Nokogiri, libxml2 and libxslt seem to be found fine, but not libiconv.

Anyone with a better knowledge of these things know how to get Nokogiri installed?

30条回答
beautiful°
2楼-- · 2020-01-23 13:52

I ran into this, this morning... after an upgrade to Mavericks. We did many things. However if anyone is having this issue here are some things to try.

I ran 'xcode-select --install' then got the command line tools installed (surprised this didn't update on the OS ugrade). I ran 'rvm implode' (I will build it back up later).

We pieced together two error output files:

~/.vagrant.d/gems/gems/nokogiri-1.6.3.1/ext/nokogiri/gem_make.out

~/.vagrant.d/gems/gems/nokogiri-1.6.3.1/ext/nokogiri/tmp/x86_64-apple-darwin12.5.0/ports/libxml2/2.8.0/configure.log

Which seemed to indicate that the c compiler was using a surprising setting.

I ran 'env'

Output contained:

...
CXX=/usr/local/opt/apple-gcc42/bin/g++-4.2
...
CC=/usr/local/opt/apple-gcc42/bin/gcc-4.2
...

These files didn't exist on the file system...

After all of these changes moving to a new terminal windows (so everything was fresh). Installation of vagrant-berkshelf (which in turn installs nokogiri) worked fine.

NOTE: when running 'env' in the fresh window there was no longer a setting for CC or CXX...

Unsure on the key part of this, or if order matters, but tried to recreate the parts that seemed to play a role in getting this to work.

查看更多
欢心
3楼-- · 2020-01-23 13:53

I had similar trouble on Mountain Lion. Turns out I had installed libiconv via rvm package previously and this is no longer necessary for ruby 1.9.3/Mountain Lion/nokogiri.

Following the advice of https://rvm.io/packages/, I deleted my $rvm_path/usr directory and rebuilt ruby 1.9.3. Thereafter installing nokogiri was a simple gem install. No messing with brew/macports/manual source installs!

查看更多
别忘想泡老子
4楼-- · 2020-01-23 13:53

According to the documentation, as of OSX 10.9 and Homebrew 9.5+, you are probably missing the development tools.

Nokogiri installation

Troubleshooting

If you have problems mentioning libiconv missing that looks something like this:

Installing nokogiri (1.6.2.1) Building nokogiri using packaged libraries.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ruby extconf.rb
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 ***

Then you are probably missing the right developer tools. This is a really easy fix:

brew unlink gcc-4.2      # you might not need this step
gem uninstall nokogiri
xcode-select --install
gem install nokogiri

This is verified working on OSX 10.9 w/ xcode’s clang compiler.

查看更多
戒情不戒烟
5楼-- · 2020-01-23 13:54

First of all make sure you follow the installation guide on nokogiri: http://nokogiri.org/tutorials/installing_nokogiri.html

After having followed the guide I still had this issue. This is how I solved it:

First of all I installed iconv using homebrew: brew install iconv

Then I uninstalled ruby, luckily this is very easy with rvm:

rvm uninstall 1.9.2        

Then I had to reinstall ruby with the following options:

CC=gcc-4.2 rvm install 1.9.2-p290 --with-iconv-dir=/usr/local/Cellar/libiconv/1.13.1

Then I create a gemset with the new ruby version:

rvm use 1.9.2@coolproject

Then I can finally install nokogiri like this:

gem install nokogiri -v=1.4.4 -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
查看更多
干净又极端
6楼-- · 2020-01-23 13:55

I had the same issue. Unfortunately the "Installing Nokogiri" doesn't cover Iconv issues. Here's how I resolved the issue.

First install homebrew, it'll make your life easier. If you already have it installed, be sure to grab the latest formulae by updating like so:

brew update

Note: In OSX 10.9+ you may need to install xCode command tools to allow you to install libiconv.

xcode-select --install

then install a newer version of libiconv

brew install libiconv

then install your gem

gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
查看更多
Viruses.
7楼-- · 2020-01-23 13:56

Looking in the mkmf file, it apear that nokogiri (or gem, I don't know) try to find dependencies in /op/local/. For me it's not the right path to search them for.

Forcing nokogiri to find the libs at the right place (I use homebrew) did the trick for me :

$ gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8/

Maybe there is something to fix in nokogiri...

HTH,

查看更多
登录 后发表回答