Skip to content

Instantly share code, notes, and snippets.

@sobstel
Created January 3, 2017 17:30
Show Gist options
  • Save sobstel/f6a490d854a2e5a214c3f2cd9c366032 to your computer and use it in GitHub Desktop.
Save sobstel/f6a490d854a2e5a214c3f2cd9c366032 to your computer and use it in GitHub Desktop.
nokogiri -> ERROR: cannot discover where libxml2 is located on your system
# `ERROR: Error installing nokogiri:
# ERROR: Failed to build gem native extension.
#
# current directory: /usr/local/var/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nokogiri-1.7.0/ext/nokogiri
# /usr/local/var/rbenv/versions/2.3.1/bin/ruby -r ./siteconf20170103-68488-r71c9j.rb extconf.rb --with-xml=/usr/local/Cellar/libxml2/ --use-system-libraries
# checking if the C compiler accepts ... yes
# checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
# Building nokogiri using system libraries.
# ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed.
# *** 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.`
gem install nokogiri -- \
--with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2 \
--use-system-libraries
# copy/paste one-liner
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2 --use-system-libraries
@bramski
Copy link

bramski commented Dec 18, 2017

So much happiness.

@tclaus
Copy link

tclaus commented May 15, 2018

Thanks, works on OSX 10.13.4 like a charm. I added a " -v '1.7.2' " right after 'nokogiri' for my needs.

@vladrose
Copy link

vladrose commented Jul 5, 2018

You are the best of the best. THX very much!

@suya55
Copy link

suya55 commented Aug 1, 2018

Thank you so much!!

@arvsr1988
Copy link

I used brews libxml2 as I got this error while using the libxml2 with macos

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

this is what i did finally

brew install libxml2
gem install nokogiri -v '1.6.8' --   --with-xml2-include=/usr/include/libxml2   --use-system-libraries

@fbukevin
Copy link

Thanks!

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

Works on macOS 10.13.6.

@roberttravispierce
Copy link

Thank you!! The one-liner helped me get out of nokogiri hell on MacOS when doing Rails dev. (MacOS 10.14)

@lisovskyvlad
Copy link

thanks!

@xiaohui-zhangxh
Copy link

thanks

@fengerzh
Copy link

fengerzh commented Feb 3, 2019

If using bundle to install gem, you can run below:

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

@avanathan
Copy link

Thank you! This helped me

@catmando
Copy link

Thanks for this...

for me libxml2 was here: /usr/local/opt/libxml2/include/libxml2

so gem install nokogiri -v '1.6.8.1' -- --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 --use-system-libraries worked for me

@xiaohui-zhangxh
Copy link

@rohitravikalra
Copy link

If using bundle to install gem, you can run below:

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

this helped.
Thanks.

@MisterSpicy
Copy link

<3

@johnerck
Copy link

Yes

Copy link

ghost commented Nov 25, 2019

On MacOS Catalina and nokogiri 1.6.8 it didn't help.

I needed to run:

brew upgrade libxml2
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"
gem install nokogiri -v '1.6.8'

@brodock
Copy link

brodock commented Jan 13, 2020

when using bundler and brew the correct flag are :

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

no need to export PKG_CONFIG_PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment