Installing Nokogiri on OSX 10.10 Yosemite

RubyGemBundlerNokogiriHomebrew

Ruby Problem Overview


I recently upgrade to the 10.10 Yosemite beta, but I'm having trouble getting Nokogiri installed. I'm using RVM and Ruby 1.9.3. I've also followed the steps here and tried following the instructions on Nokogiri's homepage.

I've installed libxml2 (2.9.1) and libxslt (1.1.28) via homebrew, and have tried using the command line tools from both my Xcode 5 install and Xcode 6 beta.

gem install nokogiri -v '1.5.5'
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
	ERROR: Failed to build gem native extension.

        /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/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
	--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/grantdavis/.rvm/rubies/ruby-1.9.3-p362/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/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:970:in `block in find_header'
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:254:in `open'
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:254:in `open'
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
	from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:969:in `find_header'
	from extconf.rb:114:in `<main>'

Anyone have an idea on how to fix these install errors?

EDIT 6/10/14: After trying for a couple days to get Nokogiri installed on OSX 10.10, I ended up abandoning the task and restored 10.9 on my machine. Several libraries and bundles need to be updated in order to work in the 10.10 environment.

Ruby Solutions


Solution 1 - Ruby

I managed to install Nokogiri under Yosemite (OS X 10.10 Preview).

Step 1: Install Brew

Skip this if brew was installed.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step 2: Install brew libs
brew tap homebrew/dupes
brew install libxml2 libxslt
brew install libiconv
Step 3: Download and install Apple Commandline Tools for 10.10

It's important that you need to restart after installation.

Link: command_line_tools_for_osx_10_10_june_2014.dmg

After restarted, you can check installation in Terminal:

> xcode-select --install
-> xcode-select: error: command line tools are already installed, use "Software Update" to install updates

This error means you have commandline tool installed correctly.

Installing Nokogiri

Try using n previous version 1.6.1 in your Gemfile, version 1.6.2.1 has issues currently with "10.10 Preview". It only works with my rbenv Ruby 2.0.0p247, failed to install on 2.1.1. You can give your existing Ruby versions a couple of tries.

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

Solution 2 - Ruby

libxml2 - 1.6.6.2 in Yosemite:

sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -- --use-system-libraries  -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-xslt-lib=/usr/local/lib --with-xslt-include=/usr/local/include

Solution 3 - Ruby

For Mac OS El Capitan:

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

Solution 4 - Ruby

This worked for me:

ARCHFLAGS="-arch x86_64" gem install nokogiri -v '1.6.0'

Solution 5 - Ruby

I had the same problem with MacPorts ruby2.1:

can not gem install nokogiri on osx10.10 with macports ruby2.1

The install starts, the cpu goes to 50% on a single core at 100%, then CPU drops to near zero, but iostat tps goes through the wall.

This helped:

# port install libiconv libxslt libxml2

# gem install nokogiri -- --use-system-libraries --with-iconv-dir=/opt/local --with-xml2-dir=/opt/local --with-xslt-dir=/opt/local

Solution 6 - Ruby

This finally worked for me:

sudo gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/

Solution 7 - Ruby

For anyone else that hasn't been able to get this to work on El Capitan, what finally worked for me was:

sudo gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-iconv-dir=/usr/local/opt/libiconv --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 --with-xslt-config=/usr/local/opt/libxslt/bin/xslt-config

I don't have macports installed, and my system is a weird hodge-podge. Forcing specific installations for each dependency is the only way that I can get Nokogiri to compile. Super annoying, but at least it works.

Solution 8 - Ruby

The instructions from the Nokogiri website worked for me on both OSX 10.9 and 10.10.

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

Solution 9 - Ruby

sudo gem update --system
sudo gem install nokogiri -v '1.6.6.2' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib

Solution 10 - Ruby

(full answer here https://gist.github.com/chrisb/4d6a09c6cc1ca2e1b14e)

It looks like Homebrew somehow depends on Ruby being in Versions/1.8 (though even Mavericks ships with 2.0). Until Homebrew addresses this, we'll symlink our system version of Ruby to the one Homebrew looks for.

Create the folder:

sudo mkdir -p /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin

Then symlink the binary:

sudo ln -s /usr/bin/ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

Solution 11 - Ruby

This worked for me:

$ brew install libxml2 libxslt  # optional?
$ brew install libiconv         # optional?
$ gem install nokogiri -v 1.6.8 -- --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2

on environment like this:

$ sw_vers -productVersion 
10.9.4
$ brew -v
Homebrew 0.9.9 (git revision aa747; last commit 2016-05-26)
$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14
  - RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [universal.x86_64-darwin13]

Solution 12 - Ruby

The only thing that worked for me was to upgrade the compiler from apple-gcc42 to gcc48:

brew uninstall apple-gcc42
brew install gcc48 # this might take an hour or so
rvm implode
\curl -sSL https://get.rvm.io | bash -s stable # reinstall RVM
rvm install ruby-1.9.3-p551
bundle update libv8 # 3.16.14.3 doesn't work but 3.16.14.7 does
bundle

Solution 13 - Ruby

If you're using OS X 10.10 and MacPorts you have to install pkgconfig as well:

sudo port install pkgconfig libxml2 libxslt libiconv

Also if you want to use MacPorts libraries automagically without adding configure options you'll need to add this to your .profile or .bashrc:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
export LDFLAGS="-L/opt/local/lib"
export CPPFLAGS="-I/opt/local/include"

And also you may want to add this to tell Nokogiri to always use your system libraries:

export NOKOGIRI_USE_SYSTEM_LIBRARIES=Y

Restart terminal after adding all these exports.

Using this configuration you can install Nokogiri using:

gem install nokogiri

Solution 14 - Ruby

I got the same error message on OS X Yosemite version 10.10.5

I had recently done various OS updates and it turned out I only needed to accept the new xcode license agreement using the following command:

sudo xcodebuild -license

Solution 15 - Ruby

I think the issue is related to the system Ruby not being found or multiple Rubies are installed.

  • Do you use RVM to manage rubies?
  • What is the output of ruby -v?

Those should be the starting point to finding a solution.

The bad interpreter error is related to a problem with the Ruby installation.

Ideally, you should start with the system Ruby, the one that ships with Xcode. So, you would uninstall Xcode completely using:

http://osxdaily.com/2012/02/20/uninstall-xcode/

Uninstall brew, rvm and reinstall them.

Solution 16 - Ruby

For me switching to Xcode 5 rather than using Xcode 6's CLI tool:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/

Solution 17 - Ruby

Install the full Xcode. It was the only thing that worked for me for old Nokogiri versions.

Solution 18 - Ruby

In my case, the error message was written below and the accordingly solution as well.

Error message:

...
libxml2 is missing.  Please locate mkmf.log to investigate how it is failing.
...

Solution:

gem install nokogiri -- --use-system-libraries --with-libxml2lib=/usr/local/opt/libxml2/lib/libxml2.a

I directly gave it the path of the library of libxml2.a

Solution 19 - Ruby

solve the "Can't write /usr/bin/nokogiri while Installing on Mac OS El Capitan" problem on mac os x:

sudo gem install nokogiri -n /usr/local/bin

Reference: https://www.bountysource.com/issues/28085261-can-t-write-usr-bin-nokogiri-while-installing-on-mac-os-ei-capitan

Solution 20 - Ruby

Just try:

xcode-select --install

Solution 21 - Ruby

This worked:

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

Source

Solution 22 - Ruby

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongdavisView Question on Stackoverflow
Solution 1 - RubyactivarsView Answer on Stackoverflow
Solution 2 - RubyxrageView Answer on Stackoverflow
Solution 3 - RubyMaximus SView Answer on Stackoverflow
Solution 4 - RubyTom ColemanView Answer on Stackoverflow
Solution 5 - RubyedxView Answer on Stackoverflow
Solution 6 - RubyManas TungareView Answer on Stackoverflow
Solution 7 - RubyramijamesView Answer on Stackoverflow
Solution 8 - RubyDaniel RomeroView Answer on Stackoverflow
Solution 9 - RubyIM_AGView Answer on Stackoverflow
Solution 10 - RubyparquarView Answer on Stackoverflow
Solution 11 - RubyNakilonView Answer on Stackoverflow
Solution 12 - RubyHew WolffView Answer on Stackoverflow
Solution 13 - RubyXeronView Answer on Stackoverflow
Solution 14 - RubyTorben JacobsenView Answer on Stackoverflow
Solution 15 - RubyfrishiView Answer on Stackoverflow
Solution 16 - RubyalexzgView Answer on Stackoverflow
Solution 17 - RubymaranoView Answer on Stackoverflow
Solution 18 - RubyIvan LinView Answer on Stackoverflow
Solution 19 - RubyviviaView Answer on Stackoverflow
Solution 20 - RubyleoyamasakiView Answer on Stackoverflow
Solution 21 - Ruby0bserver07View Answer on Stackoverflow
Solution 22 - RubySachin SinghView Answer on Stackoverflow