Installing Nokogiri on OSX 10.10 Yosemite
Asked Answered
H

22

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.

Hodeida answered 6/6, 2014 at 23:2 Comment(5)
You have to install development tools first.Substandard
I have the development tools installed. I have Xcode 6 and I've separately downloaded and installed the command line tools for 10.10.Hodeida
Hope this might help: #24092369Carnivorous
I managed to solve this same problem upgrading to ruby 2.1.2 (with rvm). After a nightmare session of gems, brews and whatnot :/Zindman
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.Hitoshi
C
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/
Carnivorous answered 10/6, 2014 at 22:1 Comment(15)
I uninstalled and reinstalled Homebrew as I was getting 'bad interpreter' then I was able to run the brew commands.Businesslike
brew install libiconv - this gave me Error: Permission denied - /usr/local/Cellar/libiconv/1.14Molybdenous
also code-select --install is giving me this - Error: Permission denied - /usr/local/Cellar/libiconv/1.14 and your above dmg link no longer workMolybdenous
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..Carnivorous
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/Aerialist
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.Foreworn
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.1Millikan
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 withoutVerde
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)"Univalve
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 Then I installed the brew dependencies: brew install libxml2 libxslt and finally nokogiri with gem install nokogiri -- --use-system-librariesBadoglio
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?Witness
This helped me, but I also needed to do this: sudo xcodebuild -license.Nita
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).Uncrowned
It took me couple of hours to make it work & with your solution works! Thanks!Pal
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 @UncrownedExasperate
H
63

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
Herron answered 3/2, 2015 at 12:19 Comment(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.)Archaeozoic
Thank you I use these options also for installing fastlane !Constipate
@DavidYeiser You can pass Nokogiri version like this 'nokogiri:1.6.1'Herron
I could use it without sudo for ruby-2.1.0Laddy
@DavidYeiser thank you, after many attempts your solution was the only one that worked for me in Yosemite!Discriminator
I got (Errno::EPERM) Operation not permitted but with a different bin dir https://mcmap.net/q/180930/-cannot-install-cocoa-pods-after-uninstalling-results-in-error the answer from @Herron 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/includeTantivy
G
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

Gabbey answered 31/1, 2016 at 11:36 Comment(1)
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/libxml2Vagus
T
18

This worked for me:

ARCHFLAGS="-arch x86_64" gem install nokogiri -v '1.6.0'
Tanny answered 20/11, 2014 at 7:7 Comment(4)
Nice one. Worked for me also. And much easier than all the other suggestions.Reedreedbird
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 i386Pudding
This is the only one that works for me without messing with macports/brewYate
Man, you saved my day!Shana
V
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
Vasileior answered 24/10, 2014 at 0:38 Comment(1)
Awsome!!! The only one that works for me as using macports! Wish I could upvote this more!Tannen
M
5

This finally worked for me:

sudo gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
Miyokomizar answered 13/5, 2015 at 4:56 Comment(0)
F
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.

Francoisefrancolin answered 27/7, 2016 at 5:32 Comment(0)
L
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
Lengthwise answered 3/11, 2014 at 10:30 Comment(0)
N
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
Nevertheless answered 12/9, 2015 at 4:27 Comment(0)
R
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
Requisition answered 10/7, 2014 at 16:10 Comment(0)
H
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]
Haberdasher answered 18/6, 2016 at 18:20 Comment(0)
H
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
Hitoshi answered 10/12, 2014 at 19:1 Comment(0)
T
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
Torn answered 26/3, 2015 at 20:46 Comment(1)
This one worked fine for me with OS X 10.9. I had to switch before to sudo xcode-select -s /Library/Developer/CommandLineTools thoughLeggett
P
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
Portsmouth answered 30/1, 2016 at 19:50 Comment(0)
M
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.

Moo answered 13/6, 2014 at 18:44 Comment(1)
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.Inextirpable
T
0

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

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
Tessler answered 8/12, 2014 at 3:40 Comment(0)
B
0

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

Benedix answered 19/3, 2015 at 11:51 Comment(0)
L
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

Loner answered 20/4, 2015 at 2:37 Comment(0)
P
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

Pronto answered 23/6, 2016 at 15:8 Comment(0)
H
0

Just try:

xcode-select --install
Hakodate answered 29/8, 2016 at 19:27 Comment(0)
C
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

Cathrine answered 7/10, 2016 at 19:26 Comment(0)
K
-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:

Kersey answered 10/6, 2014 at 10:12 Comment(3)
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: github.com/cowboyd/libv8/issues/123Hodeida
@Hodeida update gcc version and then try. see links in updated answer.Kersey
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.10Hodeida

© 2022 - 2024 — McMap. All rights reserved.