2

I am attempting to install the Nokogiri gem for use with Ruby on Rails, but I cannot get it to build no matter which packages I install. I am running Ubuntu 20.04.

I have installed all the packages from this guide on the Nokogiri website (https://nokogiri.org/tutorials/installing_nokogiri.html):

sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
gem install nokogiri

I am using RVM, so I have also installed the libgmp-dev package, which the above tutorial also recommends.

While searching for other solutions, I have also installed the following packages:

sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev

Ruby Version: 2.7.1
RVM Version: 1.29.10
Gem Version: 3.1.2

gem_make.out

current directory: /home/dan/.rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/ext/nokogiri
/usr/share/rvm/rubies/ruby-2.7.1/bin/ruby -I /usr/share/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0 -r ./siteconf20200924-8532-1t7wwwh.rb extconf.rb
checking if the C compiler accepts ... *** 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/share/rvm/rubies/ruby-2.7.1/bin/$(RUBY_BASE_NAME)
    --help
    --clean
/usr/share/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/share/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/mkmf.rb:597:in `block in try_compile'
    from /usr/share/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/mkmf.rb:544:in `with_werror'
    from /usr/share/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/mkmf.rb:597:in `try_compile'
    from extconf.rb:138:in `nokogiri_try_compile'
    from extconf.rb:162:in `block in add_cflags'
    from /usr/share/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/mkmf.rb:655:in `with_cflags'
    from extconf.rb:161:in `add_cflags'
    from extconf.rb:416:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/dan/.rvm/gems/ruby-2.7.1/extensions/x86_64-linux/2.7.0/nokogiri-1.10.10/mkmf.log

extconf failed, exit code 1

mkmf.log

"gcc -o conftest -I/usr/share/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/x86_64-linux -I/usr/share/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby/backward -I/usr/share/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0 -I.    -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable  -fPIC  conftest.c  -L. -L/usr/share/rvm/rubies/ruby-2.7.1/lib -Wl,-rpath,/usr/share/rvm/rubies/ruby-2.7.1/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic     -Wl,-rpath,'/../lib' -Wl,-rpath,'/../lib' -lruby  -lm   -lc "
gcc: error: unrecognized command line option '-Wduplicated-cond'
gcc: error: unrecognized command line option '-Wmisleading-indentation'
gcc: error: unrecognized command line option '-Wimplicit-fallthrough=0'
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

Any help would be much appreciated.

Dan Perry
  • 35
  • 8
  • Just as a *suggestion*, you could try installing the Nokogiri version `1.11.0` **beta**: https://github.com/sparklemotion/nokogiri/issues/2075 -- Errors like yours are a very common problem, and the team are hoping to prevent difficulties going forwards. – Tom Lord Sep 24 '20 at 14:41
  • I followed this steps on a docker container and i don't get any error :( – thiaguerd Sep 24 '20 at 16:35
  • @TomLord 1.11.0rc3 installs without issue for me. Thanks – Dan Perry Sep 24 '20 at 18:11
  • @TomLord Now I have the problem where Rails still wants to download the old version (1.10.10) of Nokogiri as a dependency. Is there a way of forcing Rails to use the beta version instead? – Dan Perry Sep 24 '20 at 18:34
  • @DanPerry What's your Gemfile and Gemfile.lock? I don't know why you're locked into a specific version without seeing your dependancies. In general though, you won't be using an alpha/beta/pre/candidate release version unless you specifically ask for it in the `Gemfile`. – Tom Lord Sep 25 '20 at 12:18

5 Answers5

4

You have to do a full compile of Ruby 2.7.x in order to get nokogiri 1.10.10 to install on Ubuntu 20.04.

For a clean install run:

rvm install 2.7 --disable-binary

To reinstall your existing ruby version use:

rvm reinstall 2.7 --disable-binary
lotrdev
  • 41
  • 4
2

Ubuntu 20.04. Ruby 2.7.1. Changing rvm to rbenv was fixed this error.

1

I reinstalled Ubuntu 20.04 fresh along with Ruby etc, and it worked. I don't know what went wrong, and I don't know if any of the solutions below will work.

Dan Perry
  • 35
  • 8
0

I add the same problem. On this environment :

  • ubuntu 20.04 LTS
  • ruby 2.7.0
  • gem 3.1.2
  • bundler 2.1.4,

the steps described here https://mrtan.me/post/34.html/ worked for me :

sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev

gem install nokogiri

bundle
salsa_man
  • 97
  • 1
  • 4
  • 1
    Why this is accepted answer ? Question already mention that he tried all this but still gets an error. Then how did it solve the problem ? – Vijay Meena Oct 01 '20 at 15:32
0

Can confirm. Going to rbenv worked for me as well.

Brian Piercy
  • 631
  • 1
  • 7
  • 22