Julian Popov
Julian Popov

Reputation: 17461

How to install Nokogiri on Mac OS Sierra 10.12

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.

Upvotes: 73

Views: 23519

Answers (9)

Ankit
Ankit

Reputation: 101

First install XCode from the app store

then run

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

then run

bundle install

this should work

Upvotes: 0

lraboteau
lraboteau

Reputation: 71

For Middleman

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

Upvotes: 1

NDan
NDan

Reputation: 2162

The more simple solution is to execute:

xcode-select --install
gem install nokogiri

Update

For Mojave I'm using gem install nokogiri -v '1.6.6.2' -- --use-system-libraries

Upvotes: 126

yuяi
yuяi

Reputation: 2715

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

If the above steps fail to fix the issue, what has also worked for me is running brew doctor and cleaning up any unbrewed header files.

Upvotes: 11

Niels Kristian
Niels Kristian

Reputation: 8825

If you have earlier installed nokogiri using bundler with bundle config build.nokogiri --use-system-libraries this setting will still be there. If you then meanwhile have solved your Xcode setup (as suggested as the primary method of installation in the nokogiri installation) then you might wanna try removing that fra from bundler bundle config --delete build.nokogiri and try again doing bundle install.

Upvotes: 0

Julian Popov
Julian Popov

Reputation: 17461

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="$(xcrun --show-sdk-path)"/usr/include/libxml2
bundle install

or just:

gem install nokogiri -v 1.6.8.1 -- --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2

Upvotes: 180

Quanlong
Quanlong

Reputation: 25476

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

Upvotes: 47

Rimian
Rimian

Reputation: 38418

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

Upvotes: 10

Orangenhain
Orangenhain

Reputation: 4090

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

Upvotes: 11

Related Questions