Solvedslather Bundle install fails due to nokogiri 1.6.8 problem

Yosemite 10.10.5
This was working, and now suddenly it has stopped.
The command and it's subsequent output as well as mkmf.log snippet is included below.

I notice that some of my Jenkins Mac Mini slaves when running the bundle install command install nokogiri, this one which is experiencing the failure is trying to install nokogiri 1.6.8.
What makes this difference?
============= bundle install ==============
bundle install
Fetching gem metadata from
Fetching version metadata from
Resolving dependencies...
Rubygems 2.0.14 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.9.0
Using thread_safe 0.3.5
Using claide 1.0.0
Using clamp 0.6.5
Using colored 1.2
Using mini_portile2 2.1.0
Using pkg-config 1.1.7
Using bundler 1.11.2
Using tzinfo 1.2.2
Installing nokogiri 1.6.8 with native extensions

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --use-system-libraries

Using pkg-config version 1.1.7
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.
checking for libxml-2.0... no
checking for libxslt... no
checking for libexslt... no
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.

Provided configuration options:

Gem files will remain installed in /var/folders/8r/84r5yjgs6g79sncp7rjqflnr0000gq/T/bundler20160609-42888-n8l47cnokogiri-1.6.8/gems/nokogiri-1.6.8 for inspection.
Results logged to /var/folders/8r/84r5yjgs6g79sncp7rjqflnr0000gq/T/bundler20160609-42888-n8l47cnokogiri-1.6.8/gems/nokogiri-1.6.8/ext/nokogiri/gem_make.out
Using activesupport 4.2.6
An error occurred while installing nokogiri (1.6.8), and Bundler cannot continue.
Make sure that gem install nokogiri -v '1.6.8' succeeds before bundling.

=============== SNIP mkmf.log ==============
"xcrun clang -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin14 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS -Wno-error=unused-command-line-argument-hard-error-in-future -arch x86_64 -arch i386 -c conftest.c"
warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]
1 warning generated.
warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]
1 warning generated.
checked program was:
/* begin /
1: #include "ruby.h"
3: int main() {return 0;}
end */

package configuration for libxslt is not found
have_package: checking for libxslt... -------------------- no

DL is deprecated, please use Fiddle

package configuration for libexslt is not found
have_package: checking for libexslt... -------------------- no

"xcrun clang -E -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin14 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -I/Applications/ -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS conftest.c -o conftest.i"
conftest.c:3:10: fatal error: 'libxml/xmlversion.h' file not found

include <libxml/xmlversion.h>


1 error generated.
checked program was:
/* begin /
1: #include "ruby.h"
3: #include <libxml/xmlversion.h>
end */

27 Answers

✔️Accepted Answer


I had the same error, only solution that worked for me on OSX:

xcode-select --install
gem install nokogiri

from here:

Other Answers:

This fixes it for me:

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2

I've just updated to macOS Sierra and had this issue, installing the command line tools as mentioned above by @ts-silvio worked for me

xcode-select --install

works for me.

This may happen after I reinstalled Xcode.

xcode-select --install works for me. I was unable to build the gem after updating to macOS Sierra