Home » Ruby » How to install Nokogiri on Mac OS Sierra 10.12

How to install Nokogiri on Mac OS Sierra 10.12

Posted by: admin November 30, 2017 Leave a comment

Questions:

I’m having troubles installing Nokogiri (1.6.8.1) on Mac OS Sierra 10.12.

I tried using brew install libxml2 libxslt and then referencing the install directories using command line options but it didn’t help.

Answers:

Open Xcode and, from the menu XCode -> Preferences update your Command Line Tools (Xcode 8.0).

Then do:

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

or just:

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

Questions:
Answers:

The more simple solution is to execute:

xcode-select --install
gem install nokogiri

Questions:
Answers:

Try install libxml2 first with Homebrew.

brew install libxml2

Then if installing with bundle

bundle config build.nokogiri --use-system-libraries \
  --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
bundle install

If installing directly with gem

gem install nokogiri -- --use-system-libraries \
  --with-xml2-include=$(brew --prefix libxml2)/include/libxml2

Questions:
Answers:

This might be a duplicate of gem install nokogiri -v '1.6.8.1' fails … latest accepted answer there was to do:

brew unlink xz; bundle install; brew link xz

Re-linking xz might not be necessary … if for example you only have that dependency because of the_silver_searcher (which links directly against the non-symlinked library).

Questions:
Answers:

Similar to yuяi’s answer and from Nokogiri’s help:

brew unlink xz
gem install nokogiri
brew link xz

http://www.nokogiri.org/tutorials/installing_nokogiri.html#mac_os_x

This worked for 1.7.0.1

Questions:
Answers:
gem update --system
xcode-select --install
brew unlink xz
gem install nokogiri -v '1.6.8.1'
brew link xz

Leave a Reply

Your email address will not be published. Required fields are marked *