Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby 2.1 and Nokogiri install error?

I know this is an issue that has been "solved" many times here, but I have tried all of the solutions and still can't get it to work. Here is my error:

22-01-14 17:57:56> gem install nokogiri
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
ERROR: Failed to build gem native extension.

/Users/josh/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp//ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... ERROR, review 'tmp//ports/libxml2/2.8.0/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
  --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/josh/.rvm/rubies/ruby-2.1.0/bin/ruby
    /Users/josh/.rvm/gems/ruby-2.1.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:265:in `block in execute': Failed to complete configure task (RuntimeError)
  from /Users/josh/.rvm/gems/ruby-2.1.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:257:in `chdir'
  from /Users/josh/.rvm/gems/ruby-2.1.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:257:in `execute'
  from /Users/josh/.rvm/gems/ruby-2.1.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:65:in `configure'
  from /Users/josh/.rvm/gems/ruby-2.1.0/gems/mini_portile-0.5.2/lib/mini_portile.rb:108:in `cook'
  from extconf.rb:101:in `block in <main>'
  from extconf.rb:119:in `call'
  from extconf.rb:119:in `block in <main>'
  from extconf.rb:109:in `tap'
  from extconf.rb:109:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/josh/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1 for inspection.
Results logged to /Users/josh/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/nokogiri-1.6.1/gem_make.out

When I have libxml2 installed via brew:

22-01-14 17:57:56> brew list
ab      cmake       freetype    gettext     jpeg        libksba     libvo-aacenc    lzlib       openjpeg    proj        speex       xvid
apple-gcc42 elasticsearch   freexl      giflib      json-c      liblwgeom   libvorbis   memcached   openssl     qt      sqlite      xz
apr     faac        frei0r      git     lame        libogg      libvpx      mongodb     opus        readline    texi2html   yasm
apr-util    fdk-aac     fribidi     gpp     libass      libpng      libxml2     mysql       orc     redis       theora
autoconf    ffmpeg      gd      graphviz    libevent    libspatialite   libxslt     node        pcre        rtmpdump    ttfautohint
automake    fontconfig  gdal        grep        libgeotiff  libtiff     libyaml     openconnect phantomjs   schroedinger    wkhtmltopdf
cloc        fontforge   geos        imagemagick libgpg-error    libtool     little-cms2 opencore-amr    pkg-config  sdl     x264

22-01-14 17:57:56> brew list libxml2
/usr/local/Cellar/libxml2/2.8.0/bin/xmllint
/usr/local/Cellar/libxml2/2.8.0/bin/xmlcatalog
/usr/local/Cellar/libxml2/2.8.0/bin/xml2-config
/usr/local/Cellar/libxml2/2.8.0/include/libxml2/ (47 files)
/usr/local/Cellar/libxml2/2.8.0/lib/libxml2.2.dylib
/usr/local/Cellar/libxml2/2.8.0/lib/pkgconfig/libxml-2.0.pc
/usr/local/Cellar/libxml2/2.8.0/lib/ (3 other files)
/usr/local/Cellar/libxml2/2.8.0/share/aclocal/libxml.m4
/usr/local/Cellar/libxml2/2.8.0/share/doc/ (121 files)
/usr/local/Cellar/libxml2/2.8.0/share/gtk-doc/ (55 files)
/usr/local/Cellar/libxml2/2.8.0/share/man/ (4 files)

and RVM:

22-01-14 17:57:56> rvm list

rvm rubies

=* ruby-2.1.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

and GCC:

22-01-14 17:57:56> gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.2
Thread model: posix

I have tried everything in this and other threads: "Install Nokogiri 1.6.1 under Ruby 2.0.0p353 (rvm based installation) fails (OSX Mavericks)?"

Also I don't even have Nokogiri defined in my Gemfile.


OK, I found the configure.log file:

  1 checking build system type... i386-apple-darwin13.0.2
  2 checking host system type... i386-apple-darwin13.0.2
  3 checking for a BSD-compatible install... /usr/bin/install -c
  4 checking whether build environment is sane... yes
  5 checking for a thread-safe mkdir -p... ./install-sh -c -d
  6 checking for gawk... no
  7 checking for mawk... no
  8 checking for nawk... no
  9 checking for awk... awk
 10 checking whether make sets $(MAKE)... yes
 11 checking for gcc... gcc-4.2.1
 12 checking whether the C compiler works... no
 13 configure: error: in `/Users/josh/.rvm/gems/ruby-2.1.0/gems/nokogiri-1.6.1/ext/nokogiri/tmp/ports/libxml2/2.8.0/libxml2-2.8.0':
 14 configure: error: C compiler cannot create executables
 15 See `config.log' for more details

And in the config.log I found:

83 configure:3326: checking for C compiler version
84 configure:3335: gcc-4.2.1 --version >&5
85 configure: line 3337: gcc-4.2.1: command not found
86 configure:3346: $? = 127
87 configure:3335: gcc-4.2.1 -v >&5
88 configure: line 3337: gcc-4.2.1: command not found
89 configure:3346: $? = 127
90 configure:3335: gcc-4.2.1 -V >&5
91 configure: line 3337: gcc-4.2.1: command not found
92 configure:3346: $? = 127
93 configure:3335: gcc-4.2.1 -qversion >&5
94 configure: line 3337: gcc-4.2.1: command not found
95 configure:3346: $? = 127
96 configure:3366: checking whether the C compiler works
97 configure:3388: gcc-4.2.1    conftest.c  >&5
98 configure: line 3390: gcc-4.2.1: command not found
like image 978
jwilcox09 Avatar asked Jan 23 '14 00:01

jwilcox09


People also ask

Can t install Nokogiri?

Solution. Uninstall all versions of Nokogiri on your system, and then re-resolve your dependencies (using bundle or gem install ). This error can occur when a version of Nokogiri installed for a different version of Ruby is used by an unsupported version of Ruby.

What is Ruby gem Nokogiri?

Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby. It provides a sensible, easy-to-understand API for reading, writing, modifying, and querying documents. It is fast and standards-compliant by relying on native parsers like libxml2 (C) and xerces (Java).

What is Nokogiri used for in rails?

Nokogiri is an open source library in Ruby used to read HTML and XML Basically it is used to read information from websites to use for your application.


Video Answer


1 Answers

It turned out I wasn't referencing the C compiler properly. In my ".bash_profile" I had:

export CC=gcc-4.2.1

And I replaced it with:

export CC=gcc
like image 86
jwilcox09 Avatar answered Oct 07 '22 00:10

jwilcox09