14

I'm a new to Ruby world and I need to clone an existing project.

The instructions are:

source .env.development
bundle install

But it fails with:

Using libv8 3.16.14.15
Fetching libxml-ruby 2.9.0
Installing libxml-ruby 2.9.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /Users/vlad/.rvm/gems/ruby-2.3.1/gems/libxml-ruby-2.9.0/ext/libxml
/Users/vlad/.rvm/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20181109-46682-fvgifh.rb extconf.rb --use-system-libraries
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
--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=/Users/vlad/.rvm/rubies/ruby-2.3.1/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:

  /Users/vlad/.rvm/gems/ruby-2.3.1/extensions/x86_64-darwin-18/2.3.0/libxml-ruby-2.9.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/vlad/.rvm/gems/ruby-2.3.1/gems/libxml-ruby-2.9.0 for inspection.
Results logged to /Users/vlad/.rvm/gems/ruby-2.3.1/extensions/x86_64-darwin-18/2.3.0/libxml-ruby-2.9.0/gem_make.out

An error occurred while installing libxml-ruby (2.9.0), and Bundler cannot continue.
Make sure that `gem install libxml-ruby -v '2.9.0'` succeeds before bundling.

In Gemfile:
  upnxt_community_lib_common was resolved to 1.7.49, which depends on
    upnxt_processing_lib_document was resolved to 2.0.0, which depends on
      libxml-

If I want to execute the command that is suggested "gem install libxml-ruby -v '2.9.0'" I get the same error.

Operating System: MacOS Mojave, version 10.14. Ruby version needed for the project: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin18]

I also tried this but it didn't helped.

Thanks in advance for any help!

NicuVlad
  • 2,491
  • 3
  • 28
  • 47
  • 1
    `brew install libxml2`? – Tom Lord Nov 09 '18 at 09:44
  • And if if still fails, `brew link --force libxml2`? – Tom Lord Nov 09 '18 at 09:45
  • @TomLord, I tried this and it didn't worked – NicuVlad Nov 09 '18 at 10:11
  • @NicuVlad it still says _"need libxml2"_? – Stefan Nov 09 '18 at 10:18
  • 1
    @NicuVlad It's hard to diagnose the problem when all we hear back from suggestions is "didn't help" or "didn't work". Does the error message remain identical, or did it change? If the error has changed, then we've probably made some progress and now need to address a *different* issue. – Tom Lord Nov 09 '18 at 10:23
  • @TomLord, the output was indentical – NicuVlad Nov 09 '18 at 11:33
  • All of the people answering below are explaining how to install it with the gem command. The OP mentions that he's using Bundler. These gem steps do NOT help with the bundler command. – RubyRedGrapefruit Dec 15 '19 at 22:32
  • Does this answer your question? [Why aren't "gem" and "bundle" using the same libxml2?](https://stackoverflow.com/questions/32466606/why-arent-gem-and-bundle-using-the-same-libxml2) – Korayem Mar 12 '20 at 20:19

5 Answers5

29

These steps worked for me (source)

brew install libxml2
bundle config --global build.libxml-ruby --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config"

then bundle install worked as expected

skplunkerin
  • 2,123
  • 5
  • 28
  • 40
24

I manage to fix this with the help of a colleague, if anybody else encounter this problem:

gem install libxml-ruby -v '2.9.0' -- --use-system-libraries --with-xml2-dir=/usr/local/Cellar/libxml2/2.9.8/include/libxml2/libxml/ --with-xml2-config=/usr/bin/xml2-config

Replace '2.9.0' with the libxml version that you need!

NicuVlad
  • 2,491
  • 3
  • 28
  • 47
5

It solved for me in mac by running

gem install libxml-ruby -v '3.0.0' -- --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xml2-include=/usr/local/opt/libxml2/include

Jitendra Rathor
  • 607
  • 8
  • 11
2

Just happened today.

$ brew link --force libxml2
Warning: Refusing to link macOS-provided software: libxml2
...

At first, I wasn't aware that there's a warning and it doesn't work anymore. Then found this workaround and it worked for me.

bundle config build.libxml-ruby --use-system-libraries=true --with-xml2-include=/usr/local/opt/libxml2/include/libxml2/
banyan
  • 3,837
  • 2
  • 31
  • 25
0

I've encountered many tips while googling around today. I've tried to compile them into a logical order of some things to try:

Installing/debugging libxml on mac for ruby/rails.

There's a lot on this page already. But just to point out a few extra things I've gathered from elsewhere.

To me it seems more sensible to try to get a working bundle config command than to bypass this with a gem install command. So use skplunkerin's answer, or...

The following will configure it to use the system libxml headers:

bundle config --global build.libxml-ruby --with-xml2-include=`xcrun --show-sdk-path`/usr/include/libxml2
bundle install

...which worked better for me today. The libxml-ruby gem build was having issues with the latest homebrew installed libxml vs an older system libxml.

Harry Wood
  • 2,220
  • 2
  • 24
  • 46