31
Running 'compile' for libxslt 1.1.28... OK
Running 'install' for libxslt 1.1.28... OK
Activating libxslt 1.1.28 (from /Users/Kartik/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/nokogiri-1.6.4.1/ports/x86_64-apple-darwin14.0.0/libxslt/1.1.28)...
checking for main() in -llzma... yes
checking for xmlParseDoc() in libxml/parser.h... no
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no

libxml2 is missing. Please locate mkmf.log to investigate how it is failing.

*** 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.
Raptor
  • 53,206
  • 45
  • 230
  • 366
John Smith
  • 311
  • 1
  • 3
  • 3

8 Answers8

85

i fiddled around with this for quite a while and the following worked for me..

1) install libxml2 with homebrew

brew install libxml2

2) install the gem via

sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri:1.6.4.1 -- --use-system-libraries --with-xml=/usr/local/Cellar/libxml2/
hlv
  • 1,087
  • 8
  • 6
  • 2
    This solved the issue for me: sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri – Mani Jan 29 '15 at 14:33
  • 4
    +1. I spent an hour having fun with wonderful nokogiri. But the solution was so simple! A 255 character line of super specific commands. Makes complete sense. – HotFudgeSunday Feb 19 '15 at 20:27
  • 11
    I am getting the error "libxml2 version 2.6.21 or later is required!" although the libxml in /usr/local/Cellar/... is 2.9.2. Strange. – user152468 Mar 12 '15 at 08:49
  • This is perfect. Sudo can be omitted if you are using rvm or rbenv. – Ten Bitcomb May 05 '15 at 16:37
  • @user152468, I am also getting "libxml2 version 2.6.21 or later is required". Brew installs libxml2-2.9.2 so not sure if that 2- is involved somehow? – codecowboy Jul 30 '15 at 15:50
  • Thank you. Works on OS X 10.11 too. – Mohamed El-Nakeep May 03 '16 at 23:08
  • @user152468 I ran: `sudo gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2`. I had to install the newest version of ruby though. – cbelsole Jan 20 '17 at 18:08
15

For any who are still getting "libxml2 version 2.6.21 or later is required!" message, removing --use-system-libraries from hlv's step 2 above, worked for me.

sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri:1.6.4.1 -- --with-xml=/usr/local/Cellar/libxml2/2.9.2/
Taylor Smith
  • 151
  • 1
  • 4
3

I finally ended up with this version independent line:

sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri  -n /usr/local/bin -- --with-xml=/usr/local/Cellar/libxml2/
freytag
  • 4,769
  • 2
  • 27
  • 32
3

This worked for me (assuming Xcode is installed):

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

Inspired by https://stackoverflow.com/a/28767045/1884907 (credits to lx00st)

Community
  • 1
  • 1
jakob.j
  • 942
  • 13
  • 28
  • It should be "nokogiri" instead of "nkogiri". Thanks. – maurymmarques Jun 02 '16 at 05:07
  • Or use `/usr/include/libxml2` instead of the long `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.‌platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2`. – Franklin Yu Jul 30 '16 at 22:11
  • As of today, this worked: `gem install libxml-ruby -v '3.0.0' -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries` – paneer_tikka Nov 22 '17 at 12:34
3

(For MacOX 10.12.x) Perhaps you want to brew install libxml2 and also try linking into /usr/local/ first: brew link --force libxml2, then try that gem install nokogiri -- --use-system-libraries.

conny
  • 9,973
  • 6
  • 38
  • 47
1

Using ports:

gem install nokogiri -- --use-system-libraries --with-xml=/opt/local/lib/libxml2.a
lesyk
  • 3,979
  • 3
  • 25
  • 39
0

My solution, using ports:

sudo ARCHFLAGS='-arch x86_64' gem install nokogiri -- --use-system-libraries

By default, it will compile for x86_64 and i386, architecture for i386 should disabled, because the dependencies libraries in port only provide x86_64 version by default.

alijandro
  • 11,627
  • 2
  • 58
  • 74
0

This is a bit of a rehash of all the other answers, but this worked for me:

 gem install nokogiri -v '1.6.6.2' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.16 --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2  --use-system-libraries
Ramses
  • 996
  • 4
  • 12
  • 28