Installing Nokogiri on OSX 10.10 Yosemite

一笑奈何 提交于 2019-11-27 02:49:15
activars

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/
xrage

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

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

This worked for me:

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

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
Manas Tungare

This finally worked for me:

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

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.

Daniel Romero

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
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

(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

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]

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

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

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

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

marano

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

alexzg

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

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

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.

leoyamasaki

Just try:

xcode-select --install

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

vivia

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

Sachin Singh

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!