Nokogiri 'Failed to build gem native extension' when I run bundle install
Asked Answered
B

18

70

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.

Bunin answered 15/5, 2014 at 3:20 Comment(0)
D
232

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
Decadent answered 31/7, 2014 at 20:6 Comment(8)
Thank you - this worked for me as well on Mac OS X 10.9.5 when everything else didn't.Vat
Great! Wonderful! Awesome! Outstanding! Hours of pain are over! Hell knows who wrote instruction on nokogiri.org/tutorials/installing_nokogiri.html that required me to uninstall gcc and mess with Xcode.Haugen
Thank you so much. Could somebody explain why this is this way and how to prevent in the future?Minimalist
This helped me, but on Ubuntu I had to figure out the install path using dpkg: dpkg -L libxml2-dev Using dpkg on libxml2 didn't work, only libxml2-dev (after making sure it was installed). Thanks!Fitzpatrick
I got this error :Could not locate Gemfile or .bundle/ directory after running bundle installUnyoke
Yep, this fixed my problem after upgrade to el capitan 10.11.3Tartaglia
Received this warning when running brew install libxml2. ``` Warning: libxml2 is a keg-only and another version is linked to opt. Use brew install --force if you want to install this version ``` Since it said I had one installed, (which I know why I have there) rather than force, I just skipped it. The remainder of the steps (using the one provided by the system) worked perfectly. Thank you, all, for saving me hours trying to figure this out.Swatow
Worked with Mojave also...ThanksThy
D
52

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

Downing answered 1/7, 2014 at 13:9 Comment(6)
Thank you for this! I've been Googling forever to figure this out and your solution finally installed successfully and I was able to complete the instructions to get Jekyll running (successfully) on OSX 10.9.5Ozonide
Works on Yosemite too, if that helps.Darwen
This seems to work as well: gem install nokogiri -- --with-xml2-include=/usr/local/opt/libxml2/include/libxml2Blocker
Had to change 10.9 to 10.10 (cuz Yosemite). Otherwise, it went swimmingly. Thanks!Fizz
Updated for 10.11 El Capitan: gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2Diviner
Updated for 10.13 High Sierra: gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2Denni
D
15

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/
Delwin answered 28/7, 2014 at 3:35 Comment(5)
Thanks. Saved me some time. Amazon Linux (as often) a bit more tricky than others. :)Substance
Marvelous! I've been trying to get this working all day on Amazons Ubuntu install, and your solution finally got Nokogiri built. Yay!Highhanded
Also sudo apt-get install binutils-doc cpp-doc gcc-4.8-locales gcc-multilib make autoconf automake1.9 libtool flex bison gdb gcc-doc gcc-4.8-multilib gcc-4.8-doc libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan0-dbg libtsan0-dbg libbacktrace1-dbg libquadmath0-dbg binutils-gold glibc-doc libgmp10-doc libmpfr-dev libstdc++-4.8-docTanganyika
I had to first do yum install -y gcc ruby-devel zlib-devel before this workJaneenjanek
Thank you! Worked like a charm for a clean CentOS docker image ;)Dulcine
P
4

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.

Precinct answered 15/5, 2014 at 3:33 Comment(1)
For redhat base systems use libxslt-devel and libxml2-develRobinia
T
3

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
Toritorie answered 3/7, 2014 at 6:3 Comment(0)
D
2

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
Dyslogistic answered 22/2, 2015 at 15:30 Comment(0)
F
2

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
Factoring answered 9/12, 2015 at 16:6 Comment(0)
P
2

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
Papule answered 16/9, 2016 at 3:14 Comment(0)
O
1

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'

Orb answered 15/5, 2014 at 3:40 Comment(8)
I actually have the latest version of libxml2 (2.9.1), that's what's wierd!Bunin
@Bunin do you also have the "-dev" package installed? Assuming you have Debian/Ubuntu, try sudo apt-get install libxml2-devOrb
@FabKremer, looks to me like you're using a Mac. In that case read here on how to install the latest packages: nokogiri.org/tutorials/installing_nokogiri.htmlOrb
Yes, I'm using mac. Look my edit please! I've already installed the nokogiri, have the gem in the system but that error persist while doing bundle install on my projectBunin
That link I posted tells you how to install libxml which nokogiri depends on. From the error message, it looks like nokogiri is not installed. Gem list and bundle install gems in different locations so do not rely on gem list to see the results of bundle installOrb
So the problem now is: how could I to stop the bundle install error after having downloaded the nokogiri gem following nokogiri.org/tutorials/installing_nokogiri.html steps ?Bunin
If you did for example brew install libxml2 libxslt and brew link libxml2 libxslt then you should be able to do bundle install afterwards. In your gemfile, make sure you are specifying the latest stable nokogiri (1.5.5). At the moment you have 1.6.2 specified which in not a final release.Orb
Call me stupid but nokogiri says you need later than 2.6.21, and you have 2.9.1, so why is it complaining? I have 2.7.8 and seeing the same problem. Nokogiri should be fine, as IMO 2.7.8 is greater than 2.6.21, unless I failed basic math.Elagabalus
B
1

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
Bauxite answered 22/6, 2015 at 3:26 Comment(0)
L
0

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.

Levis answered 17/7, 2014 at 20:4 Comment(0)
S
0

On Yosemite 10.10 this workaround worked for me:

gem install nokogiri -- --use-system-libraries
Suppress answered 13/2, 2015 at 1:17 Comment(0)
C
0

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
Crossing answered 5/11, 2015 at 18:28 Comment(0)
R
0

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.

Radiation answered 5/12, 2016 at 15:4 Comment(0)
D
0

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

Denumerable answered 23/3, 2017 at 20:40 Comment(0)
F
0

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.

Foveola answered 17/4, 2017 at 13:47 Comment(0)
C
0

This can be fixed by installing libxml2:

brew install libxml2
bundle config build.nokogiri --use-system-libraries
bundle install
Cards answered 22/9, 2019 at 13:30 Comment(0)
P
0

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 /
Pernell answered 25/11, 2019 at 5:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.