Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install Nokogiri on Mac OS Sierra 10.12

Tags:

ruby

nokogiri

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.

like image 693
Julian Popov Avatar asked Oct 14 '16 08:10

Julian Popov


4 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="$(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
like image 66
Julian Popov Avatar answered Nov 10 '22 01:11

Julian Popov


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

like image 32
NDan Avatar answered Nov 10 '22 01:11

NDan


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
like image 47
Quanlong Avatar answered Nov 09 '22 23:11

Quanlong


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

like image 11
Orangenhain Avatar answered Nov 09 '22 23:11

Orangenhain