Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nokogiri 'Failed to build gem native extension' when I run bundle install

I'm running bundle install and I'm getting this error:

Building nokogiri using system libraries.  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.      /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --use-system-libraries Building nokogiri using system libraries. libxml2 version 2.6.21 or later is required! *** 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     --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     --without-xml2-dir     --with-xml2-include     --without-xml2-include=${xml2-dir}/include     --with-xml2-lib     --without-xml2-lib=${xml2-dir}/lib     --with-libxml-2.0-config     --without-libxml-2.0-config     --with-pkg-config     --without-pkg-config     --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-exslt-dir     --without-exslt-dir     --with-exslt-include     --without-exslt-include=${exslt-dir}/include     --with-exslt-lib     --without-exslt-lib=${exslt-dir}/lib     --with-libexslt-config     --without-libexslt-config     --with-pkg-config     --without-pkg-config  extconf failed, exit code 1  Gem files will remain installed in /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.2.rc2 for inspection. Results logged to /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-13/2.0.0/nokogiri-1.6.2.rc2/gem_make.out An error occurred while installing nokogiri (1.6.2.rc2), and Bundler cannot continue. Make sure that `gem install nokogiri -v '1.6.2.rc2'` succeeds before bundling. 

Any ideas what could this be?

EDIT:

I also have installed nokogiri following the instructions in the tutorial, and the weird thing is that the gem was successfully installed. When I run gem list, I have nokogiri (1.6.2.1), but when running bundle install it displays the error.

like image 641
FabKremer Avatar asked May 15 '14 03:05

FabKremer


People also ask

Can t install Nokogiri gem?

Solution. Uninstall all versions of Nokogiri on your system, and then re-resolve your dependencies (using bundle or gem install ). This error can occur when a version of Nokogiri installed for a different version of Ruby is used by an unsupported version of Ruby.

What is GEM Nokogiri?

The Nokogiri gem is an incredible open-source tool that parses HTML and XML data. It is one of the most widely used gems available, and it can really take your Ruby app to another level for data with its ability to help you intuitively scrape websites.

How do I install a specific version of a gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.


2 Answers

Previous advises didn't help me, here is the solution for OS 10.9:

brew install libxml2 bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2" bundle install 
like image 86
Kir Avatar answered Sep 29 '22 10:09

Kir


On Mavericks this workaround worked for me:

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 

See: https://github.com/sparklemotion/nokogiri/issues/1099#issuecomment-43023208

like image 25
pcv Avatar answered Sep 29 '22 11:09

pcv