Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@JeffreyMFarley

This comment has been minimized.

Copy link

JeffreyMFarley commented Oct 31, 2017

Thank You!

@bramski

This comment has been minimized.

Copy link

bramski commented Dec 18, 2017

So much happiness.

@tclaus

This comment has been minimized.

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

This comment has been minimized.

Copy link

VladRose commented Jul 5, 2018

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

@suya55

This comment has been minimized.

Copy link

suya55 commented Aug 1, 2018

Thank you so much!!

@arvsr1988

This comment has been minimized.

Copy link

arvsr1988 commented Aug 8, 2018

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

This comment has been minimized.

Copy link

fbukevin commented Sep 12, 2018

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

This comment has been minimized.

Copy link

roberttravispierce commented Nov 2, 2018

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

@lisovskyvlad

This comment has been minimized.

Copy link

lisovskyvlad commented Nov 28, 2018

thanks!

@xiaohui-zhangxh

This comment has been minimized.

Copy link

xiaohui-zhangxh commented Dec 13, 2018

thanks

@fengerzh

This comment has been minimized.

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

This comment has been minimized.

Copy link

avanathan commented Feb 23, 2019

Thank you! This helped me

@catmando

This comment has been minimized.

Copy link

catmando commented Mar 13, 2019

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

This comment has been minimized.

Copy link

xiaohui-zhangxh commented Mar 13, 2019

@rohitravikalra

This comment has been minimized.

Copy link

rohitravikalra commented Jun 14, 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

this helped.
Thanks.

@MisterSpicy

This comment has been minimized.

Copy link

MisterSpicy commented Sep 12, 2019

<3

@johnerck

This comment has been minimized.

Copy link

johnerck commented Sep 18, 2019

Yes

@ghost

This comment has been minimized.

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

This comment has been minimized.

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
You can’t perform that action at this time.