Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After upgrading to macOS Mojave gem update is failing

Tags:

macos

rubygems

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.
like image 990
Jozef Dransfield Avatar asked Sep 26 '18 09:09

Jozef Dransfield


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 /

like image 102
alotofnoodles Avatar answered Nov 18 '22 03:11

alotofnoodles


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"
like image 32
codenamev Avatar answered Nov 18 '22 01:11

codenamev


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.

like image 3
Andrei R Avatar answered Nov 18 '22 01:11

Andrei R