Skip to content

Instantly share code, notes, and snippets.

@sobstel
Created January 3, 2017 17:30
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • 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
@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