27

Anyone seen this?

gem update nokogiri
Updating installed gems
Updating nokogiri
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150524-28193-cqkmxr.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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
        --enable-static
        --disable-static
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
smcracraft
  • 493
  • 6
  • 14

2 Answers2

55

I've just had this same problem on a fresh Ubuntu 14.04 box and it turns out there is a dependency for the zlib source (i.e. zlib.h) so you need to:

On Ubuntu or Debian:

sudo apt-get install zlib1g-dev

On Fedora, CentOS or RHEL:

sudo yum install zlib-devel

Or find the equivalent package for your operating system.

nc.
  • 7,179
  • 5
  • 28
  • 38
Michael M
  • 651
  • 5
  • 3
  • It worked perfectly! I had a problem when I installed rails. I tried to do following what you say and I solved my problem. Thank you – Bui Minh Duc Sep 27 '16 at 05:54
  • MacOS/OS X install xcode command line tools to get zlib & zlib-devel `xcode-select --install` – Mark Nadig Oct 26 '16 at 22:55
7

You need to install the missing dependencies, e.g.:

sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev

Then try again:

gem install nokogiri
kenorb
  • 155,785
  • 88
  • 678
  • 743
Edson Villar
  • 71
  • 1
  • 2