20

I'm working on a rails app that allows for image attachments to each use account. I'm using paperclip and amazon web services:

gem 'paperclip'
gem 'aws-sdk'

When I run bundle install, I get this message:

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out
An error occurred while installing nokogiri (1.6.5), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.5'` succeeds before bundling.

When I try running 'gem install nokogiri', I get this message:

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out

My OS is Mac OS X 10.9.4 Mavericks. What's going on here? How can I get nokogiri to install and behave properly?

Full stack trace:

Building native extensions with: '--use-system-libraries'
This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.1.2/bin/ruby 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... yes
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=/usr/local/rvm/rubies/ruby-2.1.2/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

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Katie H
  • 2,283
  • 5
  • 30
  • 51

12 Answers12

33

This works like a charm!

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

https://stackoverflow.com/a/24511149

Community
  • 1
  • 1
Katie H
  • 2,283
  • 5
  • 30
  • 51
11

On Ubuntu, try installing the following dependencies:

sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev
kenorb
  • 155,785
  • 88
  • 678
  • 743
9

Have you tried gem install nokogiri -v 1.6.5 -- --use-system-libraries?Most nokogiri errors are to do with libxml2, libxslt or libiconv config.

Nokogiri docs should give you more instructions. If the solution doesn't work, you may want to post full stack trace so others can help more.

kasperite
  • 2,460
  • 1
  • 15
  • 17
  • 1
    right, you need to install libxml2 :), run `brew install libxml2` first then try again. If you get error with libxslt and libiconv then do the same – kasperite Dec 16 '14 at 02:35
  • Thanks, I tried this, but didnt work, it keeps telling me the libxml2 is already installed, see my answer – Katie H Dec 16 '14 at 02:37
  • I really appreciate you looking into this!! :)) – Katie H Dec 16 '14 at 02:39
  • See my answer below—I haven't found it documented anywhere, but this is **the simplest** way to get nokogiri to install on Debian/Ubuntu. – Wildcard Oct 29 '15 at 18:11
  • Thanks . That worked for me. I am using ubuntu on WSL – Rpant Dec 06 '16 at 03:32
7

after upgrading to Rails 4.2.4 (which inculdes Nokogiri 1.6.6.2) on Ubuntu 14.04 (I'm using RVM) I needed to do this:

sudo apt-get install libgmp-dev

or

sudo apt-get install libgmp3-dev
equivalent8
  • 13,754
  • 8
  • 81
  • 109
  • I was trying so hard and installed almost all the libraries 10 times. FINALLY "libgmp3-dev" worked for me. Thanks. – Anuja Jan 25 '16 at 19:03
3

As per the nokogiri installation instruction installing,

sudo apt-get install zlib1g-dev

solved the issue for me.

Rimian
  • 36,864
  • 16
  • 117
  • 117
chank
  • 3,546
  • 1
  • 14
  • 22
2

Since the OP was referencing bundle install which I happened to use as well I think it is worth pointing out the Installing Nokogiri page which eventually revealed the most elegant solution (which worked for me also on Mac OS X 10.8.5):

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

This instructs bundler to install nokogiri as in the answers of @kasperite

Patru
  • 4,481
  • 2
  • 32
  • 42
2

I solved this by installing the xcode dependencies that Nokogiri needs to be installed:

xcode-select --install

After that run bundle install again and it should work.

Alexander Luna
  • 5,261
  • 4
  • 30
  • 36
1

Package that did it:

apt-get install libghc-zlib-dev

Other possible candidate:

zlib1g-dev on 12.04

found it here

Tamer
  • 33
  • 1
  • 6
1

To take from dylanjhunt's awesome answer on Github, just in case anyone hasn't tried it,

Just to add to this, I was having a very similar issue that was resolved by updating dev tools.

xcode-select --install

Hoping someone sees this that had not tried doing this yet and it helps.

beckah
  • 1,543
  • 6
  • 28
  • 61
0

I didn't get the same error message as you, but I wanted to note what I finally found as the extraordinarily simple solution for installing nokogiri on Ubuntu:

Turns out the nokogiri build process depends on patch.

Run: sudo apt-get install patch

I was working on a VM (a vagrant box, actually), which is why I didn't already have patch installed.

The error I got (after a lot of other stuff that looked like an error but was actually just a warning) was:

Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-pc-linux-gnu/ports/libxml2/2.9.2... OK
Running patch with /var/lib/gems/1.9.1/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch...
Running 'patch' for libxml2 2.9.2... ERROR, review '/var/lib/gems/1.9.1/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-pc-linux-gnu/ports/libxml2/2.9.2/patch.log' to see what happened.

I've deleted the log by now (the above was in my terminal session), but the patch.log file referenced above was absurdly simple; it just said something like patch not found.

Boy did I feel silly for all the digging around I did installing libraries trying to fix it! :)

Wildcard
  • 1,302
  • 2
  • 20
  • 42
0

install gcc first

in *buntu : apt-get install gcc

after that U may requer most dev libs, such as libxml2 / zlib / etc. see build log(path in my case) : /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.6.8.1/mkmf.log for string like - fatal error: zlib.h: No such file or directory

guest
  • 1
0

I had the same issue earlier today. I had updated my xcode and had not agreed to the terms yet. Running sudo xcodebuild -license and agreeing got my bundle working again.

fguillen
  • 36,125
  • 23
  • 149
  • 210