Pregunta

I'm running bundle install and I'm getting this error:

Building nokogiri using system libraries.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --use-system-libraries
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** 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.0/usr/bin/ruby
    --help
    --clean
    --use-system-libraries
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-pkg-config
    --without-pkg-config
    --with-exslt-dir
    --without-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib
    --with-libexslt-config
    --without-libexslt-config
    --with-pkg-config
    --without-pkg-config

extconf failed, exit code 1

Gem files will remain installed in /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.2.rc2 for inspection.
Results logged to /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-13/2.0.0/nokogiri-1.6.2.rc2/gem_make.out
An error occurred while installing nokogiri (1.6.2.rc2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.2.rc2'` succeeds before bundling.

Any ideas what could this be?

EDIT:

I also have installed nokogiri following the instructions in the tutorial, and the weird thing is that the gem was successfully installed. When I run gem list, I have nokogiri (1.6.2.1), but when running bundle install it displays the error.

¿Fue útil?

Solución

Previous advises didn't help me, here is the solution for OS 10.9:

brew install libxml2
bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2"
bundle install

Otros consejos

On Mavericks this workaround worked for me:

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2

See: https://github.com/sparklemotion/nokogiri/issues/1099#issuecomment-43023208

On Amazon Linux, I had to install these two devel libraries, and then specify the include path for libxml2

$ yum install libxml2-devel libxslt-devel
$ gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2/

I also had some problems installing nokogiri, Than I installed following packages, It worked for me:

libxslt-dev
libxml2-dev
libruby1.8
libreadline-ruby1.8
libopenssl-ruby
libxml2

I am not sure, which one was exactly needed.

http://nokogiri.org/tutorials/installing_nokogiri.html. Refer to this link and install the dependencies required for nokogiri. Then run this

  • bundle config build.nokogiri --use-system-libraries
  • bundle install

On Yosemite 10.10.1, this step did not help (may be it works for others)

gem install nokogiri -- --use-system-libraries

Basically issue on my local was due to libxml2, so following workaround did the trick

bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2

bundle install

This worked for OS X El Capitan:

brew install libxml2 libxslt libiconv 

After running the'brew install libxml2 libxslt libiconv ' You may find, that they are already installed. No worries, it never hurts to double check.

sudo gem install nokogiri -v '1.6.7' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib

bundle install

Change the version of nokogiri, if needed. e.g.

sudo gem install nokogiri -v '1.6.5' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib

For mac, the reason why it failed is that you didn't have latest Xcode Developer Tools. Nokogiri has already been packaged with libxml2. For the lack of latest Xcode Developer Tools, it can't build native extensions.

To update Xcode Developer Tools using:

xcode-select --install

And then:

gem install nokogiri

If you fix it by using

gem install nokogiri -- --use-system-libraries

may get a similar warning later:

WARNING: Nokogiri was built against LibXML version 2.9.3, but has dynamically loaded 2.9.0

The error states that your libxml2 system library is out of date. You need version 2.6.21 or later.

On my Debian/ubuntu system, nokogiri compiles for me, and I can see I have version 2.9.1

dpkg -l | grep libxml2-dev
ii  libxml2-dev:amd64                      2.9.1+dfsg1-3                      amd64        Development files for the GNOME XML library

You have three options here.

  1. Check if your OS package manager provides a newer version of libxml2 library

  2. Download the latest libxml2 source code, compile and install it

  3. Manually specify an older version of nokogiri in your Gemfile that works with older libxml2 library. The nokogiri changelog shows that you won't have this problem with nokogiri version 1.4.7 (although using an older version can expose you to security issues)

For solution #3, you would put this in your gemfile: gem 'nokogiri', '1.4.7'

On Yosemite 10.10 the following steps solved my issues completely:

  • sudo xcode-select -switch /Library/Developer/CommandLineTools
  • gem uninstall nokogiri libxml-ruby
  • gem install nokogiri

This thread on GitHub gave me the trick I needed get Nokogiri 1.6.2 to install:

My ~/.gitconfig had the setting autocrlf = input. When I remove this setting the nokogiri build succeeds.

On Yosemite 10.10 this workaround worked for me:

gem install nokogiri -- --use-system-libraries

For #CentOS I needed to do the following:

gem update --system
yum install libxml2-devel libxslt-devel ruby-devel
gem install nokogiri -- --use-system-libraries

This is an old thread, but I hit similar issues, and the solution in my case was quite different to those posted so far.

After some digging, I found this thread: https://github.com/bundler/bundler/issues/2648#issuecomment-25124800

It talks about bundler using a different version of ruby to that used by gem.

From OP's paste, we can see bundler is using the Mac system copy of ruby: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby

In my case I found that gem was coming from brew; which gem gave /usr/local/bin/gem which symlinks to /Cellar/ruby/2.3.3/bin/gem. My guess is that the OP's case was the same.

So, gem and bundler are not working off the same ruby installation, which explains why the OP sees this:

When I run gem list, I have nokogiri (1.6.2.1), but when running bundle install it displays the error.

In my case, I simply ran gem install bundler, which made bundler start using the brew version of ruby, and all problems disappeared.

On OSX 10.12 (Sierra) this worked for me:

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2

I had this exact issue. I run a rails environment on a mac. After I upgraded from Yosemite to Sierra I believe thats when it started.

To fix the problem I just had to install xcode command line tools. I don't know if the Sierra upgrade removed them or what.

xcode-select --install

(this will install the xcode command line tools)

Also another symptom..things like git status won't work. After this i was able to do rails new appname and it was fine.

This can be fixed by installing libxml2:

brew install libxml2
bundle config build.nokogiri --use-system-libraries
bundle install

This is a problem with macOS, I tried everything above but nothing was working, So tried to install versions of libxml2 but everything in vain.

So use the below command to you will be in good shape then,

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top