Skip to main content

Impossible to install Nokogiri - OSX Mojave 10.14.2

Gems / Libraries • Asked by cbellorini

Hey Everyone,
Since the recent update (10.14.2) Nokogiri gem cannot be installed in my app.

When I run bundle install , I get the following error:

./siteconf20190109-70456-1diyett.rb extconf.rb --use-system-libraries
checking if the C compiler accepts -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE
-fstack-protector-strong -O2 -pipe... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future...
no
Building nokogiri using system libraries.
Using pkg-config gem version 1.3.2
checking for libxml-2.0... yes
checking for libxslt... yes
checking for libexslt... 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.

I went to the nokigiri installation tutorial, but their solution does not work.

Do you have any idea to solve this problem?


It says libxml2 is missing. so you might have just missed installing that dependency.

That's a simple brew install libxml2 to fix. 👍


I already install libxml2 but after having installed it the error is the same.


I'm still on High Sierra for my main computer, but let me open up Macbook which I upgraded.

My guess is that it's simply looking in the wrong folder still.

Did you try this line I had in the guide?

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

I noticed that the Nokogiri docs had a slightly different one.

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Yes, I tried your line from the guide.
then I ran gem install nokogiri
I got a another error:

RROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    current directory: /Users/charbell/.rvm/gems/ruby-2.4.4/gems/nokogiri-1.10.0/ext/nokogiri
/Users/charbell/.rvm/rubies/ruby-2.4.4/bin/ruby -I /Users/charlesbellorini/.rvm/rubies/ruby-2.4.4/lib/ruby/site_ruby/2.4.0 -r ./siteconf20190109-76119-6rjiq6.rb extconf.rb
checking if the C compiler accepts -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
Using mini_portile version 2.4.0
checking for iconv.h... yes
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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.

Thank you very much for your help.


Getting closer it sounds like.

Try this and see if that helps.

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

Alternatively, this one does the seame thing but doesn't use the libraries from homebrew in case the above fails:

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

According to Nokogiri's issues, they might have a fix coming out at some point soon so you won't have to do these workarounds. https://github.com/sparklemotion/nokogiri/pull/1851


Both of them does not work. it comes with the same error : libxml2 is missing. Please locate mkmf.log to investigate how it is failing.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.