Ask A Question

Notifications

You’re not receiving notifications from this thread.

Impossible to install Nokogiri - OSX Mojave 10.14.2

cbellorini asked in Gems / Libraries

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?

Reply

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

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

Reply

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

Reply

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
Reply

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.

Reply

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

Reply

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.

Reply

Still having this error in 1.10.7 in 2020, any update on potential resolution?

Reply

try this:

bundle config build.nokogiri --use-system-libraries
bundle install
Reply

brew install libxml2
bundle config build.nokogiri --use-system-libraries --with-xml2-include=/usr/include/libxml2/

I have this in my notes and I got the answer on Stackoverflow.

Reply

it's really enlightening

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,400+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.