54

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.

gdavis
  • 2,556
  • 1
  • 20
  • 25
  • 1
    `You have to install development tools first.` – Chris Ledet Jun 06 '14 at 23:05
  • 1
    I have the development tools installed. I have Xcode 6 and I've separately downloaded and installed the command line tools for 10.10. – gdavis Jun 06 '14 at 23:13
  • Hope this might help: http://stackoverflow.com/questions/24091869/installing-nokogiri-on-osx-10-10-yosemite/24151574#24151574 – activars Jun 10 '14 at 22:02
  • I managed to solve this same problem upgrading to ruby 2.1.2 (with rvm). After a nightmare session of gems, brews and whatnot :/ – djromero Oct 04 '14 at 10:47
  • I have a very similar problem: OS X 10.10 (Yosemite), RVM 1.26.3, Ruby 1.9.3 (ruby-1.9.3-p551), Nokogiri 1.6.1. I've tried various ideas from SO and elsewhere, but no luck so far. – Hew Wolff Dec 09 '14 at 22:30

22 Answers22

79

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/
pkamb
  • 33,281
  • 23
  • 160
  • 191
activars
  • 1,664
  • 13
  • 15
  • I uninstalled and reinstalled Homebrew as I was getting 'bad interpreter' then I was able to run the brew commands. – LpLrich Jun 11 '14 at 14:56
  • 1
    brew install libiconv - this gave me Error: Permission denied - /usr/local/Cellar/libiconv/1.14 – satyajit Jun 19 '14 at 14:28
  • also code-select --install is giving me this - Error: Permission denied - /usr/local/Cellar/libiconv/1.14 and your above dmg link no longer work – satyajit Jun 19 '14 at 14:32
  • apple just released an update 1.0 to 10.10, try the upgrade see if that fixes the issue. you need 'sudo' when seeing those permission errors.. – activars Jun 19 '14 at 16:00
  • If you're installing nokogiri via bundler, use the following before installing: `bundle config build.nokogiri --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/` – swrobel Sep 09 '14 at 01:00
  • I also faced the same problem today and problem was same some missing lib libconv.... You just need to install the developer tools (run xcode-select --install in command line) and voila after that just reuse bundle install/or gem install whatever you were using earlier. For me homebrew was working fine. – Pradeep Kumar Mishra Oct 18 '14 at 13:40
  • for 1.6.1 I am getting the message `couldn't understand kern.osversion `14.0.0'` in mkmf.log located in ~/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.1/ the installation of 1.6.3.1 works nicely but not 1.6.1. I use the gem `backup` which depends on 1.6.1 – nils petersohn Oct 20 '14 at 20:00
  • Your point about xcode-select is interesting and important: having xcode installed is not enough; it will give access to clang but apparently not the right libraries. After the download from the prompt it installed cleanly for me without – nruth Oct 21 '14 at 21:49
  • The instructions above contain an old URL for installing Brew, the new one is `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"` – Chad Robinson Oct 22 '14 at 14:39
  • 2
    I found that on a fresh Yosemite 10.10 install with ruby-2.0.0-p594 installed via rvm that I had to first [symlink gcc-4.2](http://stackoverflow.com/a/12031707/384938) Then I installed the brew dependencies: `brew install libxml2 libxslt` and finally nokogiri with `gem install nokogiri -- --use-system-libraries` – subblue Oct 30 '14 at 11:32
  • The link for installing the Apple Command Line Tools for 10.10 has restricted access. Would anyone with access be willing to post the instructions? – rainbowsorbet Mar 27 '15 at 23:48
  • This helped me, but I also needed to do this: `sudo xcodebuild -license`. – kstevens715 Apr 16 '15 at 01:40
  • 5
    I need to use `gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2` it also worked on 10.9 (after changing the sdk version). – Nilloc Jun 18 '15 at 03:30
  • It took me couple of hours to make it work & with your solution works! Thanks! – Katarzyna Sep 15 '15 at 21:46
  • For El Capitan, the above gets updated to the following: `sudo gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/` -- thanks to @Nilloc – zagros Oct 31 '15 at 19:22
62

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
xrage
  • 4,690
  • 4
  • 25
  • 31
  • 6
    This worked for me, but I had to add -v '1.6.1' to it: `sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -v '1.6.1' -- --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` I could install the latest nokogiri gem, but running bundle install didn't work unless I used the specific version it asked for. (Maybe this is a project config.? Don't know enough about Ruby to know, I just know this is what finally worked for me.) – David Yeiser Mar 06 '15 at 20:59
  • 1
    Thank you I use these options also for installing fastlane ! – ecaste Mar 20 '15 at 10:00
  • @DavidYeiser You can pass Nokogiri version like this 'nokogiri:1.6.1' – xrage Apr 21 '15 at 06:24
  • 2
    I could use it without `sudo` for ruby-2.1.0 – tbuehl Aug 24 '15 at 10:23
  • @DavidYeiser thank you, after many attempts your solution was the only one that worked for me in Yosemite! – NoChecksum Nov 11 '15 at 21:33
  • I got `(Errno::EPERM) Operation not permitted` but with a different bin dir http://stackoverflow.com/a/31783856/109079 the answer from @xrage worked a treat (getting default version `1.6.8` as of this date): `sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -n /usr/local/bin -- --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` – Partly Cloudy Jul 02 '16 at 00:54
22

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

Maximus S
  • 10,759
  • 19
  • 75
  • 154
  • This worked for me: sudo gem install nokogiri -v '1.6.8' -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 – Bruno Medeiros Jun 16 '16 at 21:52
18

This worked for me:

ARCHFLAGS="-arch x86_64" gem install nokogiri -v '1.6.0'
Tom Coleman
  • 3,037
  • 18
  • 16
  • Nice one. Worked for me also. And much easier than all the other suggestions. – iceydee Dec 08 '14 at 15:01
  • I'm still dying on zlib: `Undefined symbols for architecture i386: "_gzdirect", referenced from: ___xmlParserInputBufferCreateFilename in libxml2.a(xmlIO.o) "_gzdopen", referenced from: _xmlGzfileOpenW in libxml2.a(xmlIO.o) _xmlGzfileOpen_real in libxml2.a(xmlIO.o) "_gzopen", referenced from: _xmlGzfileOpenW in libxml2.a(xmlIO.o) _xmlGzfileOpen_real in libxml2.a(xmlIO.o) ld: symbol(s) not found for architecture i386` – PeterT Feb 26 '15 at 18:19
  • This is the only one that works for me without messing with macports/brew – JosephH Aug 03 '15 at 11:58
  • Man, you saved my day! – Igor Barinov Sep 02 '15 at 21:11
7

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
edx
  • 1,317
  • 1
  • 12
  • 14
5

This finally worked for me:

sudo gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Manas Tungare
  • 607
  • 6
  • 13
5

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.

ramijames
  • 164
  • 1
  • 9
3

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Daniel Romero
  • 1,581
  • 1
  • 20
  • 33
3
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
IM_AG
  • 520
  • 5
  • 17
2

(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
parquar
  • 61
  • 3
2

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]
Nakilon
  • 34,866
  • 14
  • 107
  • 142
1

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
Hew Wolff
  • 1,489
  • 8
  • 17
1

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
Xeron
  • 11
  • 4
  • This one worked fine for me with OS X 10.9. I had to switch before to `sudo xcode-select -s /Library/Developer/CommandLineTools` though – user9869932 Oct 07 '16 at 12:26
1

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
0

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
frishi
  • 862
  • 1
  • 10
  • 27
  • Mac OS has shipped with Ruby pre-installed for a long time. It isn't installed by Xcode, so "start with the system Ruby, the one that ships with Xcode" is just confusing. Uninstalling Xcode isn't going to remove the system Ruby, only removing the system would do that and you don't want to go there. – the Tin Man Jun 23 '15 at 03:17
0

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

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
alexzg
  • 845
  • 8
  • 8
0

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

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
marano
  • 722
  • 6
  • 9
0

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

Ivan Lin
  • 51
  • 1
  • 4
0

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
vivia
  • 2,983
  • 1
  • 13
  • 8
0

Just try:

xcode-select --install
Blue
  • 22,608
  • 7
  • 62
  • 92
0

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

0bserver07
  • 3,390
  • 1
  • 28
  • 56
-1

Try this out:

Install these packages in the given order:

brew install libxml2 libxslt
brew link libxml2 libxslt
gem install nokogiri

Try updating gcc version:

Community
  • 1
  • 1
Sachin Singh
  • 7,107
  • 6
  • 40
  • 80
  • I gave that a shot, and it still doesn't install. I believe its an issue installing the libv8, and I've opened an issue here: https://github.com/cowboyd/libv8/issues/123 – gdavis Jun 10 '14 at 15:05
  • @gdavis update gcc version and then try. see links in updated answer. – Sachin Singh Jun 10 '14 at 16:47
  • I've tried updating GCC, as well as went through all the posts you mentioned here. Nothing that worked for previous OSX versions seems to work for 10.10 – gdavis Jun 10 '14 at 20:55