Failing to install Nokogiri gem
Asked Answered
V

12

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
Vernievernier answered 16/12, 2014 at 2:18 Comment(0)
V
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

Vernievernier answered 16/12, 2014 at 2:38 Comment(1)
It worked, but only after I updated the path to libxml2 (for future users)Denson
H
11

On Ubuntu, try installing the following dependencies:

sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev
Hydrazine answered 30/1, 2017 at 4:17 Comment(0)
H
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.

Hawkes answered 16/12, 2014 at 2:26 Comment(5)
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 sameHawkes
Thanks, I tried this, but didnt work, it keeps telling me the libxml2 is already installed, see my answerVernievernier
I really appreciate you looking into this!! :))Vernievernier
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.Wash
Thanks . That worked for me. I am using ubuntu on WSLUnloose
M
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
Madeleinemadelena answered 6/10, 2015 at 9:2 Comment(1)
I was trying so hard and installed almost all the libraries 10 times. FINALLY "libgmp3-dev" worked for me. Thanks.Lefthander
S
3

As per the nokogiri installation instruction installing,

sudo apt-get install zlib1g-dev

solved the issue for me.

Sucrase answered 25/5, 2015 at 20:25 Comment(2)
zlib1g-dev is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.Fidelia
Worked for me as well on Ubuntu 16.04.Psychopath
A
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

Adaptation answered 29/12, 2014 at 21:34 Comment(0)
A
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.

Arrogant answered 9/12, 2016 at 23:24 Comment(0)
A
1

Package that did it:

apt-get install libghc-zlib-dev

Other possible candidate:

zlib1g-dev on 12.04

found it here

Andaman answered 12/9, 2015 at 18:26 Comment(0)
K
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.

Kiyohara answered 27/3, 2017 at 15:29 Comment(0)
W
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! :)

Wash answered 29/10, 2015 at 18:7 Comment(0)
D
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

Dev answered 11/10, 2016 at 9:15 Comment(0)
S
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.

Scheelite answered 19/6, 2018 at 15:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.