5

I tried to do a bundle install on my Rails app, and it got stuck at "installing nokogiri". The instructions at the bottom of the error message say

Make sure that `gem install nokogiri -v '1.5.5'` succeeds before bundling.

Once I saw that, I tried

gem install nokogiri -v '1.5.5'

It told me there was an error installing Nokogiri. I'm using Ruby 1.9.2 on a Mac, in a Rails 3.0.4 app.

Can anyone suggest a fix?

Installing nokogiri (1.5.5) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/mm/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
checking for libxml/parser.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/mm/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
    --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-iconv-dir
    --without-iconv-dir
    --with-iconv-include
    --without-iconv-include=${iconv-dir}/include
    --with-iconv-lib
    --without-iconv-lib=${iconv-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-pkg-config
    --without-pkg-config
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --with-libiconv-config
    --without-libiconv-config
    --with-pkg-config
    --without-pkg-config
/Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
    from extconf.rb:114:in `<main>'


Gem files will remain installed in /Users/mm/.rvm/gems/ruby-1.9.2-p290@rails304/gems/nokogiri-1.5.5 for inspection.
Results logged to /Users/mm/.rvm/gems/ruby-1.9.2-p290@rails304/gems/nokogiri-1.5.5/ext/nokogiri/gem_make.out
An error occurred while installing nokogiri (1.5.5), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.5.5'` succeeds before bundling.

brew doctor says there's no problems. brew update says everything's already updated. When I do brew install libxslt libxml2 libiconv I get this error:

Error: No available formula for libiconv
Apple distributes libiconv with OS X, you can find it in /usr/lib.
Some build scripts fail to detect it correctly, please check existing
formulae for solutions.

When I try to do gem install nokogiri I get this error:

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

        /Users/mm/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for libxml/parser.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/mm/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
    --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-iconv-dir
    --without-iconv-dir
    --with-iconv-include
    --without-iconv-include=${iconv-dir}/include
    --with-iconv-lib
    --without-iconv-lib=${iconv-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-pkg-config
    --without-pkg-config
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-libiconv-config
    --without-libiconv-config
/Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/mm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
    from extconf.rb:115:in `<main>'
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
BrainLikeADullPencil
  • 11,313
  • 24
  • 78
  • 134

3 Answers3

5

Assuming you have not installed Homebrew:

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

brew doctor

to make sure everything ok

brew update

In order to be able to install libiconv

brew tap homebrew/dupes

brew install libxslt libxml2 libiconv
brew link libxslt libxml2 libiconv

gem install nokogiri
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Eugene Rourke
  • 4,934
  • 1
  • 22
  • 24
  • I should install Xcode? It's already installed...Did you mean uninstall? – BrainLikeADullPencil Jan 01 '13 at 18:52
  • My brew update failed, so I haven't been able to try the rest of your answer. Since the brew update problem is a different issue, I made a new question for it. After it's fixed, I'll try the rest of your solution http://stackoverflow.com/questions/14113427/brew-update-failed – BrainLikeADullPencil Jan 01 '13 at 19:20
  • can't get it to work. Brew doctor and brew update say everything's fine, but when I follow your instructions after that, it's not working. I've updated the OP. – BrainLikeADullPencil Jan 01 '13 at 22:11
0

If you are using Ubuntu try:

sudo apt-get install libxslt-dev libxml2-dev
gem install nokogiri

If you are using Mac OS maybe try "Why does installing Nokogiri on Mac OS fail with libiconv is missing?".

Community
  • 1
  • 1
uokesita
  • 191
  • 1
  • 11
0

For me the problem was fixed with these:

bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java

gem install nokogiri

Shows this message on "bundle update"