sergiokopplin/indigo

Issues installing the 'nokogiri' gem

ashishtibrewal opened this issue ยท 12 comments

Hi @sergiokopplin and other Indigo users !

I followed all the necessary step as mentioned in the README.md file but I haven't been able to install the 'nokogiri' gem. I know that its prerequisites are libxml2 (Macports link) and libxslt (Macports link). I've installed these prerequisites using the MacPorts package manager.

I'm running on the following system:
Operating System: OS X El Capitan 10.11.3
Ruby: ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
RubyGems: version 2.6.2
Node.js: version v4.2.6
npm: version 2.14.17
jekyll: jekyll 3.1.2
bundler: Bundler version 1.11.2

Any help would be much appreciated.

Thanks.

Ashish

P.S. I get the following error - it still says libxml2 is missing even though I've installed it. Is there a workaround this?

Ashishs-MacBook-Pro:indigo-gh-pages ashishtibrewal$ bundle install
Fetching gem metadata from http://rubygems.org/..........
Fetching version metadata from http://rubygems.org/...
Fetching dependency metadata from http://rubygems.org/..
Using rake 10.5.0
Using RedCloth 4.2.9
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4
Using thread_safe 0.3.5
Using addressable 2.3.8
Using coffee-script-source 1.10.0
Using execjs 2.6.0
Using colorator 0.1
Using colored 1.2
Using ffi 1.9.10
Using multipart-post 2.0.0
Using gemoji 2.1.0
Using net-dns 0.8.0
Using public_suffix 1.5.3
Using sass 3.4.21
Using rb-fsevent 0.9.7
Using kramdown 1.9.0
Using liquid 3.0.6
Using mercenary 0.3.5
Using rouge 1.10.1
Using safe_yaml 1.0.4
Using jekyll-feed 0.3.1
Using mini_portile2 2.0.0
Using jekyll-paginate 1.1.0
Using jekyll-sitemap 0.10.0
Using rdiscount 2.1.8
Using redcarpet 3.3.3
Using terminal-table 1.5.2
Using parallel 1.6.1
Using yell 2.0.5
Using posix-spawn 0.3.11
Using yajl-ruby 1.2.1
Using bundler 1.11.2
Using jekyll-textile-converter 0.1.0
Using tzinfo 1.2.2
Using coffee-script 2.4.1
Using ethon 0.8.1
Using rb-inotify 0.9.7
Using faraday 0.9.2
Using jekyll-sass-converter 1.3.0
Installing nokogiri 1.6.7.2 with native extensions

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

current directory: /private/var/folders/dq/pc9156z1727gxcpzmyydsk6h0000gn/T/bundler20160324-20711-1dn8ltenokogiri-1.6.7.2/gems/nokogiri-1.6.7.2/ext/nokogiri
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20160324-20711-ij4edg.rb extconf.rb --use-system-libraries
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 system libraries.
checking for xmlParseDoc() in libxml/parser.h... no
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no

libxml2 is missing.  Please locate mkmf.log to investigate how it is failing.

***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-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-xml2lib
    --without-xml2lib
    --with-libxml2lib
    --without-libxml2lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/folders/dq/pc9156z1727gxcpzmyydsk6h0000gn/T/bundler20160324-20711-1dn8ltenokogiri-1.6.7.2/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.7.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/folders/dq/pc9156z1727gxcpzmyydsk6h0000gn/T/bundler20160324-20711-1dn8ltenokogiri-1.6.7.2/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /var/folders/dq/pc9156z1727gxcpzmyydsk6h0000gn/T/bundler20160324-20711-1dn8ltenokogiri-1.6.7.2/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.7.2/gem_make.out
Using pygments.rb 0.6.3
Using activesupport 4.2.5.1
Using jekyll-coffeescript 1.0.1
Using typhoeus 0.8.0
Using listen 3.0.6
Using sawyer 0.6.0
An error occurred while installing nokogiri (1.6.7.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7.2'` succeeds before bundling.

@ashishtibrewal, i'm looking this. Thank you for reporting the problem.

I managed to get it to work using the following:
sudo gem install nokogiri -n /Library/Ruby/Gems/2.0.0/gems/ -- --use-system-libraries --with-xml2-include=/usr/include/libxml2/ --with-xml2-lib=/usr/lib/

When running bundle install, I was unable to get much information on what actually caused the problem so I tried installing just the nokogiri gem using the following command: sudo gem install nokogiri and I got the following output.

Ashishs-MacBook-Pro:ashishtibrewal.github.io ashishtibrewal$ sudo gem install nokogiri
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/ext/nokogiri
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20160324-28598-1azsql.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.
Using mini_portile version 2.0.0
checking for iconv.h... yes
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:

Building Nokogiri with a packaged version of libxml2-2.9.2
with the following patches applied:
    - 0001-Revert-Missing-initialization-for-the-catalog-module.patch
    - 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch
    - 0003-Stop-parsing-on-entities-boundaries-errors.patch
    - 0004-Cleanup-conditional-section-error-handling.patch
    - 0005-CVE-2015-1819-Enforce-the-reader-to-run-in-constant-.patch
    - 0006-Another-variation-of-overflow-in-Conditional-section.patch
    - 0007-Fix-an-error-in-previous-Conditional-section-patch.patch
    - 0008-CVE-2015-8035-Fix-XZ-compression-support-loop.patch
    - 0009-Updated-config.guess.patch
    - 0010-Fix-parsering-short-unclosed-comment-uninitialized-access.patch
    - 0011-Avoid-extra-processing-of-MarkupDecl-when-EOF.patch
    - 0012-Avoid-processing-entities-after-encoding-conversion-.patch
    - 0013-CVE-2015-7497-Avoid-an-heap-buffer-overflow-in-xmlDi.patch
    - 0014-CVE-2015-5312-Another-entity-expansion-issue.patch
    - 0015-Add-xmlHaltParser-to-stop-the-parser.patch
    - 0016-Detect-incoherency-on-GROW.patch
    - 0017-CVE-2015-7500-Fix-memory-access-error-due-to-incorre.patch
    - 0018-CVE-2015-8242-Buffer-overead-with-HTML-parser-in-pus.patch
    - 0019-Do-not-print-error-context-when-there-is-none.patch
    - 0020-xmlStopParser-reset-errNo.patch
    - 0021-Reuse-xmlHaltParser-where-it-makes-sense.patch

Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:

    gem install nokogiri -- --use-system-libraries
        [--with-xml2-config=/path/to/xml2-config]
        [--with-xslt-config=/path/to/xslt-config]

If you are using Bundler, tell it to use the option:

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

Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-apple-darwin15/ports/libxml2/2.9.2... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0003-Stop-parsing-on-entities-boundaries-errors.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0004-Cleanup-conditional-section-error-handling.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0005-CVE-2015-1819-Enforce-the-reader-to-run-in-constant-.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0006-Another-variation-of-overflow-in-Conditional-section.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0007-Fix-an-error-in-previous-Conditional-section-patch.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0008-CVE-2015-8035-Fix-XZ-compression-support-loop.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0009-Updated-config.guess.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0010-Fix-parsering-short-unclosed-comment-uninitialized-access.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0011-Avoid-extra-processing-of-MarkupDecl-when-EOF.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0012-Avoid-processing-entities-after-encoding-conversion-.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0013-CVE-2015-7497-Avoid-an-heap-buffer-overflow-in-xmlDi.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0014-CVE-2015-5312-Another-entity-expansion-issue.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0015-Add-xmlHaltParser-to-stop-the-parser.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0016-Detect-incoherency-on-GROW.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0017-CVE-2015-7500-Fix-memory-access-error-due-to-incorre.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0018-CVE-2015-8242-Buffer-overead-with-HTML-parser-in-pus.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0019-Do-not-print-error-context-when-there-is-none.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0020-xmlStopParser-reset-errNo.patch... OK
Running git apply with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/patches/libxml2/0021-Reuse-xmlHaltParser-where-it-makes-sense.patch... OK
Running 'configure' for libxml2 2.9.2... OK
Running 'compile' for libxml2 2.9.2... ERROR, review '/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/ext/nokogiri/tmp/x86_64-apple-darwin15/ports/libxml2/2.9.2/compile.log' to see what happened. Last lines are:
========================================================================
  "_gzwrite", referenced from:
      _xmlGzfileWrite in libxml2.a(xmlIO.o)
  "_inflate", referenced from:
      _xmlNanoHTTPRead in libxml2.a(nanohttp.o)
  "_inflateEnd", referenced from:
      _xmlNanoHTTPFreeCtxt in libxml2.a(nanohttp.o)
  "_inflateInit2_", referenced from:
      _xmlNanoHTTPScanAnswer in libxml2.a(nanohttp.o)
  "_libiconv", referenced from:
      _xmlIconvWrapper in libxml2.a(encoding.o)
  "_libiconv_close", referenced from:
      _xmlFindCharEncodingHandler in libxml2.a(encoding.o)
      _xmlCharEncCloseFunc in libxml2.a(encoding.o)
  "_libiconv_open", referenced from:
      _xmlFindCharEncodingHandler in libxml2.a(encoding.o)
ld: symbol(s) not found for architecture i386
collect2: error: ld returned 1 exit status
make[2]: *** [xmllint] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
========================================================================
*** 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
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build
/Library/Ruby/Gems/2.0.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:366:in `block in execute': Failed to complete compile task (RuntimeError)
    from /Library/Ruby/Gems/2.0.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:337:in `chdir'
    from /Library/Ruby/Gems/2.0.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:337:in `execute'
    from /Library/Ruby/Gems/2.0.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:111:in `compile'
    from /Library/Ruby/Gems/2.0.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:150:in `cook'
    from extconf.rb:289:in `block (2 levels) in process_recipe'
    from extconf.rb:182:in `block in chdir_for_build'
    from extconf.rb:181:in `chdir'
    from extconf.rb:181:in `chdir_for_build'
    from extconf.rb:288:in `block in process_recipe'
    from extconf.rb:187:in `tap'
    from extconf.rb:187:in `process_recipe'
    from extconf.rb:478:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.7.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.7.2/gem_make.out

This uses the default libxml2 and libxslt libraries that come with the nokogiri gem and the linker generates the errors because it is unable to resolve some symbols (this can be seen above). Instead, I tried using the system libxml2 (and libxslt) libraries installed in /usr/lib/ (with their header files located in /usr/include/libxml2/) with the following command: sudo gem install nokogiri -n /Library/Ruby/Gems/2.0.0/gems/ -- --use-system-libraries --with-xml2-include=/usr/include/libxml2/ --with-xml2-lib=/usr/lib/. Note that the -n /Library/Ruby/Gems/2.0.0/gems/ is required or else it tries to write to /usr/bin/ and this is not permitted since the introduction of System Integrity Protection (SIP) in OS X El Capitan.

@ashishtibrewal, sorry about the delay.
I'm gonna look this issue this week ok?


Thank you again for reporting the problem.

Did you solve this?
I don't know ruby really well, but you tried to delete the repo and clone again?


Can you run jekyll without problems?

Yes, I did. ๐Ÿ˜ƒ There's no problems with your repository or Jekyll (and they both work perfectly on my system now), it's something to do with the dependencies of gems listed in your Gemfile. The problems arose when running bundle install, which installs all the required gems mentioned in the Gemfile and their dependencies. So I'm guessing that the nokogiri gem was a dependency for one of the gems listed in your Gemfile. By default, bundle install failed to complete due to it being unable to install the nokogiri gem. Instead of letting bundle automatically install this dependency, I decided to install it manually using sudo gem install nokogiri -n /Library/Ruby/Gems/2.0.0/gems/ -- --use-system-libraries --with-xml2-include=/usr/include/libxml2/ --with-xml2-lib=/usr/lib/ which uses the system libxml2 library files instead of using the default library that comes with the gem itself. This is specified by using --use-system-libraries --with-xml2-include=/usr/include/libxml2/ --with-xml2-lib=/usr/lib/ โ€” these are the directories where I found the default library files (Note that it might differ for other people and/or other systems). The -n /Library/Ruby/Gems/2.0.0/gems/ was used to set the gem install destination; this can also be achieved by setting the GEM_HOME environment variable using export GEM_HOME=/Library/Ruby/Gems/2.0.0/gems/ (Refer to the RubyGems documentation for further information). I chose this since all my Ruby gems are installed in this directory and I had to run it with sudo since this directory is owned by root. You can also run gem env to get information on your system's gem environment. Running it on my system, I get the following output:

Ashishs-MacBook-Pro:ashishtibrewal.github.io ashishtibrewal$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.2
  - RUBY VERSION: 2.0.0 (2015-12-16 patchlevel 648) [universal.x86_64-darwin15]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
  - USER INSTALLATION DIRECTORY: /Users/ashishtibrewal/.gem/ruby/2.0.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - SPEC CACHE DIRECTORY: /Users/ashishtibrewal/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-15
  - GEM PATHS:
     - /Library/Ruby/Gems/2.0.0
     - /Users/ashishtibrewal/.gem/ruby/2.0.0
     - /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /opt/local/bin
     - /opt/local/sbin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /opt/X11/bin
     - /usr/local/git/bin
     - /Library/TeX/texbin

There's been numerous issues regarding this that have been reported previously, both on GitHub and StackOverflow.

You should also have a look at the official documentation. This provides detailed information on the installation procedure for Nokogiri on different systems.

P.S. I've never programmed in Ruby at all. ๐Ÿ˜ I actually spent a few hours trying to fix this issue. ๐Ÿ™ˆ

Thank you for this list of reported issues.

I think if someone get this same problem, they can take a look in this issue to see how to solve looking on these links.


I'm putting this in the readme, in the "how to" section.


Thank you for reporting that! If you have any other problems, just tell me!

FYI @sergiokopplin I had to go through quite a bit of pain to get this up and running on my El Capitan Macbook. I did a write-up of my success recipe in case it helps others: https://gist.github.com/AGresvig/31f780b85394612957e7af44bc29837d

I also had a lot of pain getting this up on running on windows via Vagrant + VirtualBox. I plan on putting together a polished Vagrant package that should make this easier for all users. I have an early version here, but that version isn't really stable yet.


Related - replace Stylus with SASS

@sergiokopplin one more thing which is kind of related, all this pain to ensure a setup MUST be done because of the need to use stylus, which also means you can't update any css without working with your full dev environment.

I am in a unique situation where most of the day I can only use the Github website (can't install any dev software), so I wanted to be able to fully edit the site without needing to recompile on my own computer. I realized that Jekyll has SASS support build in, so I converted the entire styling to using SASS on my fork (I have not yet filled in any template to that fork).

GitHub pages can even inline the sass after compiling it, so the template works just as slick as before but is less dependent on external libraries.

I don't know if you would consider making this shift, but I believe that it would be very helpful for users if they could have a version of the template that requires NO development environment setup, they can just edit via github.com, or edit/upload files directly with git and let the server do all the compiling.

I've been making a lot of changes to the template while assembling my own site, but I'm trying to keep track of the improvements I'm making so I can break them out back to the template for others to use.

@jehartzog i'm moving this to another issue ok? I guess we have to talk about!

Had similar issues. This tidbit was what made bundle install succeed. I tried several of the solutions above and they just weren't coming together. This one made it possible.

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

bundle install

This is what worked for me (Lubuntu 16.04.2).

sudo apt-get install zlib1g-dev

I managed to work this on macOS sierra v10.12 by:
sudo gem install nokogiri -n /Library/Ruby/Gems/2.0.0/gems/ -- --use-system-libraries --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2
I believe the trick is to find the path to your local libxml2