user762579
user762579

Reputation:

rails cannot install nokogiri w Mavericks & rbenv

running OSX 10.9.4 and XCode 5.1.1, I switched recently from rvm to Rbenv, so I need to reinstall some gems, not a big deal, but...

I am stuck w Nokogiri gem installation, even after downloading and installing october version of the XCode command line tool and running :

sudo xcode-select -s /Library/Developer/CommandLineTools/

I also installed libxml2 libxslt w brew

I am still getting an error, is there any way to solve this issue ?

    yves$ gem install nokogiri
    Building native extensions.  This could take a while...
    Building nokogiri using packaged libraries.
    ERROR:  Error installing nokogiri:
        ERROR: Failed to build gem native extension.

        /Users/yves/.rbenv/versions/2.1.2/bin/ruby extconf.rb
    Building nokogiri using packaged libraries.
    checking for iconv.h... *** 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/yves/.rbenv/versions/2.1.2/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
    /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
    You have to install development tools first.
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:587:in `try_cpp'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:1067:in `block in have_header'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:321:in `open'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:321:in `open'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:1066:in `have_header'
        from extconf.rb:103:in `have_iconv?'
        from extconf.rb:148:in `block (2 levels) in iconv_prefix'
        from extconf.rb:90:in `preserving_globals'
        from extconf.rb:143:in `block in iconv_prefix'
        from extconf.rb:120:in `each_iconv_idir'
        from extconf.rb:137:in `iconv_prefix'
        from extconf.rb:427:in `block in <main>'
        from extconf.rb:161:in `block in process_recipe'
        from extconf.rb:154:in `tap'
        from extconf.rb:154:in `process_recipe'
        from extconf.rb:422:in `<main>'

    extconf failed, exit code 1

    Gem files will remain installed in /Users/yves/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/nokogiri-1.6.3 for inspection.
    Results logged to /Users/yves/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.3/gem_make.out

when installing libxml2 libxslt I got a warning , it may interfere with the nokogiri installation ?

             yves$ brew install libxml2 libxslt
        ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/libxml2-2.9
        ######################################################################## 100.0%
        ==> Pouring libxml2-2.9.1.mavericks.bottle.1.tar.gz
        ==> Caveats
        This formula is keg-only, so it was not symlinked into /usr/local.

        Mac OS X already provides this software and installing another version in
        parallel can cause all kinds of trouble.

        Generally there are no consequences of this for you. If you build your
        own software and it requires this formula, you'll need to add to your
        build variables:

            LDFLAGS:  -L/usr/local/opt/libxml2/lib
            CPPFLAGS: -I/usr/local/opt/libxml2/include

what should i do next ? thanks for your advices

Upvotes: 2

Views: 2588

Answers (3)

Biscuit
Biscuit

Reputation: 21

I have found the solution on one of the forums:

https://github.com/sparklemotion/nokogiri/issues/1111

After almost a week of searching this finally did the trick:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri -- --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib

GL

Upvotes: 2

Rahul
Rahul

Reputation: 63

I got the same issue few days ago and this thread helped me

https://github.com/sparklemotion/nokogiri/issues/1111

Finally the command which worked for me

gem install nokogiri -- --with-xslt-dir=/usr/local/opt/libxslt

Upvotes: 0

FeifanZ
FeifanZ

Reputation: 16316

I got the same error a few weeks ago. This is how I solved it:

You'll have to install the broken libraries manually. Use Homebrew, which is a package manager for OS X. Make sure you update first brew update, then install the libraries:

brew install libxml2 libxslt
brew link libxml2 libxslt

You may have to install libiconv from source:

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar xvfz libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local/Cellar/libiconv/1.13.1
make
sudo make install

And then you should be able to install the gem.

Quoted from documentation here: http://nokogiri.org/tutorials/installing_nokogiri.html#homebrew_09

You may also need to run rbenv rehash after installing the libraries.

Upvotes: 3

Related Questions