Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.3.0/gems/libxml-ruby-3.1.0/ext/libxml
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20180926-80978-eoqfjh.rb extconf.rb
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** 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:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/$(RUBY_BASE_NAME)
--with-xml2-config
--without-xml2-config
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
extconf failure: need libxml2.
Install the library or try one of the following options to extconf.rb:
--with-xml2-config=/path/to/xml2-config
--with-xml2-dir=/path/to/libxml2
--with-xml2-lib=/path/to/libxml2/lib
--with-xml2-include=/path/to/libxml2/include
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/libxml-ruby-3.1.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/libxml-ruby-3.1.0 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/libxml-ruby-3.1.0/gem_make.out
Updating nokogiri
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.

- 5,410
- 4
- 22
- 39

- 524
- 4
- 11
3 Answers
The error is due to macOS Mojave has stopped placing the standard header files in /usr/include
, keeping them only inside the XCode directory.
You can verify this by running ls /usr/include
and most likely this directory does not exist anymore. On contrary, the usual trick by running xcode-select --install
will not solve the problem.
The fix is to run legacy installer provided by Apple that will install the header files to /usr/include
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

- 1,093
- 10
- 12
-
Thanks, this does help however Nokogiri is still failing to install, the problem is I didn't install Nokogiri it seems to be coming from there being an Nokogiri gem installed in the system path, which I don't seem to be able to remove. – Jozef Dransfield Oct 04 '18 at 20:09
-
This solution worked for me when attempting to do a `sudo gem update` on macOS Mojave 10.14.1. Thanks. – CoBrA2168 Nov 14 '18 at 02:41
-
I did the above but could not solve my problem. Then I reinstall ruby 2.3.3 and it worked! Thanks. – arthur bryant Dec 06 '18 at 07:41
-
Fixed my issue: The file "/usr/include/iconv.h" is missing in your build environment, which means you haven't installed Xcode Command Line Tools properly. – colsen Feb 08 '19 at 05:43
-
While I believe there are various choices to solve the issue here, this one is most suitable because my guess is there's gotta be other libraries having the same problem as libxml, but other solutions only take care of this specific lib. – Stan666 Feb 27 '19 at 09:16
-
Struggled to install fastlane for 3 days and above fix helped me. – Sudheer Kumar Palchuri May 13 '19 at 03:47
-
Great! Forgot this problem again when I upgraded to 10.14.6 - after that one line everything works, again :-) Had the issue when building PySide2 v. 5.14 – Christian Tismer Jul 31 '19 at 12:43
If you are using homebrew, the recommended approach is to tell pkg-config
where it can find the libxml2 library:
brew reinstall libxml2
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"

- 2,203
- 18
- 24
-
Neither the accepted answer worked nor this answer worked for me. I got it working by running the command provided in https://github.com/twilio/twilio-ruby/issues/315#issuecomment-453697013. – Vishal Feb 19 '19 at 20:23
-
This did it for me as well, on Catalina 10.15.2. Thank you mate! – Iuliana Cosmina Dec 18 '19 at 10:09
Also, you may have outdated bundle config, which is in the way. Run bundle config build.nokogiri --use-system-libraries
and it'll give you a warning and show what config you currently have. I was following all guides and reinstalled all gems and even ruby a few times only to find out that config was set to use a path that doesn't exist anymore.

- 4,904
- 5
- 25
- 26