7

I've tried to install Nokogiri 1.6.1 under Ruby and RVM but is failing with the following error:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/Users/lmo0/.rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb 
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin13.0.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin13.0.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... ERROR, review 'tmp/x86_64-apple-darwin13.0.0/ports/libxslt/1.1.26/configure.log' to see what happened.
*** 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
    --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/lmo0/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
/Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:265:in `block in execute': Failed to complete configure task (RuntimeError)
    from /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:257:in `chdir'
    from /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:257:in `execute'
    from /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:65:in `configure'
    from /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:108:in `cook'
    from extconf.rb:101:in `block in <main>'
    from extconf.rb:131:in `call'
    from extconf.rb:131:in `block in <main>'
    from extconf.rb:122:in `tap'
    from extconf.rb:122:in `<main>'


Gem files will remain installed in /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/nokogiri-1.6.1 for inspection.
Results logged to /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/nokogiri-1.6.1/ext/nokogiri/gem_make.out
kenorb
  • 155,785
  • 88
  • 678
  • 743
Maverick
  • 1,293
  • 1
  • 19
  • 39
  • What's in `tmp/x86_64-apple-darwin13.0.0/ports/libxslt/1.1.26/configure.log`? – CDub Jan 02 '14 at 19:59
  • Do you have Xcode installed or the Xcode tools? – Noah Clark Jan 02 '14 at 20:29
  • Do you have both `libxml2` and `libxslt` installed? – Noah Clark Jan 02 '14 at 20:30
  • ```checking for grep that handles long lines and -e... configure: error: no acceptable grep could be found in /Users/lmo0/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/bin:/Users/lmo0/.rvm/gems/ruby-2.0.0-p247/bin:/Users/lmo0/.rvm/gems/ruby-2.0.0-p247@global/bin:/Users/lmo0/.rvm/rubies/ruby-2.0.0-p247/bin:/Users/lmo0/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/s``` – Maverick Jan 02 '14 at 20:31
  • You might want to try installing `grep` via homebrew... That may help with your problem. – CDub Jan 02 '14 at 20:42
  • 1
    installing a GNU grep (brew install grep) https://github.com/sparklemotion/nokogiri/issues/935 – Maverick Jan 02 '14 at 20:54
  • it seems that running ```homebrew install grep``` did actually add ggrep to /usr/local/bin and now need to just create a symlink – Maverick Jan 02 '14 at 21:25
  • `grep` is built into Mac OS. There's absolutely no reason to install an additional instance of it. Type `which grep` at the command-line. If it doesn't show up, your PATH is messed up, or you somehow deleted it. – the Tin Man Jan 05 '14 at 09:05
  • 1
    well it seems that there is a problem with the `grep` that comes with osx mavericks and adding the GNU grep just solved my problem. There is an explanation on the Nokogiri github project that lead me to this solution. https://github.com/sparklemotion/nokogiri/issues/935 – Maverick Jan 05 '14 at 18:57
  • Not sure if the problem, but you running Mac OS Maverick? Did you update Xcode? Open and accept the the new rules? And try again ... – Ricardo Rodrigues Jan 31 '14 at 11:20
  • @Maverick Thx. Your suggestion worked for me and I duplicated it as an answer for visibility (since I've probably spent way too much time on this multiple times now). – epylinkn Feb 01 '14 at 17:59
  • Possible duplicate of [nokogiri gem installation error](http://stackoverflow.com/questions/24251494/nokogiri-gem-installation-error) – kenorb Jan 30 '17 at 04:04

5 Answers5

7

Check your grep version and install latest via brew:

$ grep --version
grep (BSD grep) 2.5.1-FreeBSD

$ brew install grep --default-names

# If above fails, you probably need to tap
$ brew tap homebrew/dupes
$ brew install grep --default-names

$ grep --version
grep (GNU grep) 2.14.56-1e3d

From (this nokogiri issue)[https://github.com/sparklemotion/nokogiri/issues/935]: "recent versions of OSX come with BSD grep, while older ones came with GNU grep. And that, your build script, perhaps requires GNU grep"

Stolen from Maverick's comment and duplicated here as an answer and not a comment because I've now run into this issue several times and would love to save someone else the headache. =X

epylinkn
  • 1,128
  • 12
  • 16
  • after running `brew install grep --default-names`, I had to close and re-open my terminal before `grep --version` showed the GNU version. – myowz May 12 '14 at 19:47
3

You can try the solution which I used so far to fix the same...

Remove all older libxml-ruby and nokogiri

use below command for the same

sudo gem uninstall nokogiri libxml-ruby

then you can try out the version of nokogiri, was having issue. THat should works perfect.

sudo gem install nokogiri -v '1.6.1' 

Much similar answer reported by Dan but some little bit change. Thanks.

Rameshwar Vyevhare
  • 2,699
  • 2
  • 28
  • 34
0

I wrote a post on this after dealing with it myself. No need for homebrew.

There was a few issues I ran into, the first one being that the development tools cannot be found, and the second one that the libxml is too old.

Run the following commands in the rubyconsole:

$ sudo xcode-select -switch /Library/Developer/CommandLineTools
$ gem uninstall nokogiri libxml-ruby
$ gem install nokogiri
Dan
  • 173
  • 2
  • 8
0

Turned out there is a bit simpler solution:

Remove this line in your ~/.bashrc or ~/.bash_profile file:

GREP_OPTIONS="--color=always"

with this one:

export GREP_OPTIONS="--color=auto"

This way you won't need to install any duplicates. Thanks to MrPowers @ Nokogiri Issues.

jibiel
  • 8,175
  • 7
  • 51
  • 74
-1

manually ./configure 'include' and 'lib' locations helped me out. libxml2 source layout is a bit strange, so i ended up with alike options:

gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib

of course, version numbers depend upon what is actually installed. at the time of this writing there version were in the brew.

in my case /usr/local/Cellar/libxml2/2.9.1/include/libxml2 contains a single directory named libxml and /usr/local/Cellar/libxml2/2.9.1/lib contains libxml2.2.dylib libxml2.a libxml2.dylib pkgconfig xml2Conf.sh: these are what the script is looking for, no other combination made it compile using system libraries.

using homebrew nokogiri can be installed with neither outdated nor incompatible (recent) libxml2 and libxslt libraries as pointed out in this gist. working fine and fast for me.

jitter
  • 434
  • 8
  • 16