17

Trying to install Nokogiri I’m getting the following error

Maxims-MacBook-Air:ScrapingTheApple maximveksler$ gem install nokogiri
Fetching: nokogiri-1.6.2.1.gem (100%)
Building native extensions.  This could take a while...
Building nokogiri using packaged libraries.
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /Users/maximveksler/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
-----
libiconv is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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=/Users/maximveksler/.rvm/rubies/ruby-2.1.2/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

extconf failed, exit code 1

Gem files will remain installed in /Users/maximveksler/.rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /Users/maximveksler/.rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.2.1/gem_make.out
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151

10 Answers10

31

The nokogiri install tutorial provides the solution:

# bash
brew unlink gcc
gem uninstall nokogiri
xcode-select --install
gem install nokogiri

If you don't have Xcode 6.1, yet, you may install it from the apple developer download site (section additional tools), as described in this blog post.

fiedl
  • 5,667
  • 4
  • 44
  • 57
  • I've done this several times now, every time forgetting that this is the easiest and quickest solution. Even if you have Xcode installed and you've been using it, running `Xcode-select --install` is still needed. – LunaCodeGirl Apr 08 '15 at 17:03
  • Works also with macOS Sierra. – fiedl Oct 07 '16 at 14:56
16

I suggest an update to Oskar's answer, replace MacOSX10.9.sdk to MacOSX10.10.sdk, tested on OS X 10.10

gem install nokogiri -- \
--with-iconv-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib \
--with-iconv-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include
tbaranes
  • 3,560
  • 1
  • 23
  • 31
ryaneof
  • 161
  • 1
  • 6
8

I was successfull with:

gem install nokogiri -- \
--with-iconv-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib \
--with-iconv-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
julienc
  • 19,087
  • 17
  • 82
  • 82
Oskar Gargas
  • 95
  • 1
  • 6
6

without brew and other stuff:

xcode-select --install 
gem install nokogiri -- --use-system-libraries
Valery Kvon
  • 4,438
  • 1
  • 20
  • 15
5

In my case I had upgraded Xcode and forgot to install the command line tools so install was not able to run compiler.

The following installs the command line tools:

xcode-select --install

Sani Elfishawy
  • 663
  • 1
  • 7
  • 14
4

Just in case if some one is still not able to resolve it as I do with the above mentioned solution, then this is the alternate

gem install nokogiri -- --user-system-libraries

or using bundle

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

bundle install

Thanks to http://www.nokogiri.org/tutorials/installing_nokogiri.html

Community
  • 1
  • 1
Bilal Ahmed
  • 182
  • 6
3

This seems to be get nokogiri to install, not sure yet about the operational state.

brew install libiconv
gem install nokogiri -- --with-iconv-include=/usr/local/opt/libiconv/include/ --with-iconv-lib=/usr/local/opt/libiconv/lib/

Install log:

Maxims-MacBook-Air:ScrapingTheApple maximveksler$ gem install nokogiri -- --with-iconv-include=/usr/local/opt/libiconv/include/ --with-iconv-lib=/usr/local/opt/libiconv/lib/
Building native extensions with: '--with-iconv-include=/usr/local/opt/libiconv/include/ --with-iconv-lib=/usr/local/opt/libiconv/lib/'
This could take a while...
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
    - 0001-Fix-parser-local-buffers-size-problems.patch
    - 0002-Fix-entities-local-buffers-size-problems.patch
    - 0003-Fix-an-error-in-previous-commit.patch
    - 0004-Fix-potential-out-of-bound-access.patch
    - 0005-Detect-excessive-entities-expansion-upon-replacement.patch
    - 0006-Do-not-fetch-external-parsed-entities.patch
    - 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
    - 0008-Improve-handling-of-xmlStopParser.patch
    - 0009-Fix-a-couple-of-return-without-value.patch
    - 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
    - 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

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

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

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

However, note that nokogiri does not necessarily support all versions
of libxml2.

For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
Building libxslt-1.1.28 for nokogiri with the following patches applied:
    - 0001-Adding-doc-update-related-to-1.1.28.patch
    - 0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch
    - 0003-Initialize-pseudo-random-number-generator-with-curre.patch
    - 0004-EXSLT-function-str-replace-is-broken-as-is.patch
    - 0006-Fix-str-padding-to-work-with-UTF-8-strings.patch
    - 0007-Separate-function-for-predicate-matching-in-patterns.patch
    - 0008-Fix-direct-pattern-matching.patch
    - 0009-Fix-certain-patterns-with-predicates.patch
    - 0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch
    - 0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch
    - 0014-Fix-for-bug-436589.patch
    - 0015-Fix-mkdir-for-mingw.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxslt.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

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

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

    bundle config build.nokogiri --use-system-libraries
    bundle install
************************************************************************
Successfully installed nokogiri-1.6.2.1
Parsing documentation for nokogiri-1.6.2.1
Installing ri documentation for nokogiri-1.6.2.1
Done installing documentation for nokogiri after 4 seconds
1 gem installed
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
  • 1
    The hyphen in your command right after `nokogiri` was wrong. This worked for me `gem install nokogiri -- --with-iconv-include=/usr/local/opt/libiconv/include/ --with-iconv-lib=/usr/local/opt/libiconv/lib/` – crcastle Aug 09 '14 at 05:20
  • @crcastle Fixed. Caused by Mac auto replace for text. – Maxim Veksler Oct 12 '14 at 16:30
0

on 10.9 with XCode 6.1 i had to throw in --use-system-libraries because the customized libxslt was dying.

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

natbro
  • 1,038
  • 12
  • 13
0

I was experiencing this problem as well, turns out for me it was a result of having installed macports under Mavericks, and not having migrating the setup to Yosemite.

Following the instructions here:

http://trac.macports.org/wiki/Migration

Allowed me to install the older version of Nokogiri (1.5.x) that was a dependency of rspec-puppet

Andrew
  • 580
  • 5
  • 13
-1

I had the same problem, after installing command line tool,

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

Doesn't necessarily work as it keeps saying check the software update(it's already the latest version). Instead, I used sudo gem install nokogiri --pre which worked in the end

Undo
  • 25,519
  • 37
  • 106
  • 129
Chris
  • 1