2

I'm working on a rails project which uses ruby 2.1.5. I downloaded rvm, installed ruby 2.1.5 and am currently using that. I'm on Ubuntu 18.04. I receive the error below when I run bundle install

Also when I try gem install nokogiri -v '1.6.7.2' as directed, it installs just fine. I could not find another question where this was the case.

I looked at this question Error while installing Nokogiri (1.6.7) on El Capitan and tried all the solutions. This may be a different issue I am having. It might be related to rvm, but I am not sure.

$ bundle install
Fetching gem metadata from https://rubygems.org/........
Using rake 11.1.2
Using CFPropertyList 2.3.3
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.4
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Fetching nokogiri 1.6.7.2
Installing nokogiri 1.6.7.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/media/mcgoy/CD25-ED8E/Upwork/EVSlideShow/Rails/vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.7.2/ext/nokogiri
/usr/share/rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20190123-15188-1qpzj0b.rb extconf.rb
--use-system-libraries
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.1.5/bin/ruby
    --help
    --clean
/usr/share/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/mkmf.rb:456: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.1.5/lib/ruby/2.1.0/mkmf.rb:571:in `block in try_compile'
    from /usr/share/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/mkmf.rb:522:in `with_werror'
    from /usr/share/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/mkmf.rb:571:in `try_compile'
    from extconf.rb:80:in `nokogiri_try_compile'
    from extconf.rb:87:in `block in add_cflags'
    from /usr/share/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/mkmf.rb:621:in `with_cflags'
    from extconf.rb:86:in `add_cflags'
    from extconf.rb:336:in `<main>'

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

/media/mcgoy/CD25-ED8E/Upwork/EVSlideShow/Rails/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.7.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/media/mcgoy/CD25-ED8E/Upwork/EVSlideShow/Rails/vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.7.2
for inspection.
Results logged to
/media/mcgoy/CD25-ED8E/Upwork/EVSlideShow/Rails/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.7.2/gem_make.out

An error occurred while installing nokogiri (1.6.7.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7.2' --source 'https://rubygems.org/'` succeeds
before bundling.

In Gemfile:
  rails was resolved to 4.2.4, which depends on
    actionmailer was resolved to 4.2.4, which depends on
      actionpack was resolved to 4.2.4, which depends on
        actionview was resolved to 4.2.4, which depends on
          rails-dom-testing was resolved to 1.0.7, which depends on
            nokogiri

But as you can see, when I run gem install nokogiri -v '1.6.7.2' it looks like there is no problem

$ gem install nokogiri -v 1.6.7.2
Building native extensions. This could take a while...
Successfully installed nokogiri-1.6.7.2
Parsing documentation for nokogiri-1.6.7.2
Done installing documentation for nokogiri after 2 seconds
1 gem installed
Randall Coding
  • 463
  • 5
  • 15

3 Answers3

2

as per reference here Installing Nokogiri

gem update --system
xcode-select --install # Then agree to the terms, even if you have done this before!
gem install nokogiri

# if that's still not working uninstall the old nokogiri 
gem uninstall nokogiri

that option above for mac os and for ubuntu already mention by javier (in other answer, if the problem persist my suggestion you do gem uninstall nokogiri first and then do gem install nokogiri -v '1.6.7.2'

widjajayd
  • 6,090
  • 4
  • 30
  • 41
  • Those instructions are for OSX, can I use that for Ubuntu? And what is xcode-select? – Randall Coding Jan 23 '19 at 17:27
  • 1
    xcode-select just for mac os , it's package library (almost same with ubuntu when you do sudo apt-get install ), my suggestion uninstall first and then install with gem install nokogiri -v '1.6.7.2' – widjajayd Jan 24 '19 at 01:28
2

These are the instructions for ubuntu docs

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

For rvm

sudo apt-get install libgmp-dev

Build with system libraries

sudo apt-get install libxml2-dev libxslt1-dev

Install

gem install nokogiri --use-system-libraries
Javier Menéndez Rizo
  • 2,138
  • 3
  • 12
  • 22
1

I fixed it, but it may be an unsatisfying answer. I went through all of the advice, installed various dependencies, changed various settings. Nothing seemed to work. Then I deleted the project folder and pulled it again from Github, reinstalled rvm, ran bundle install again and it all worked normally.

So what was the one thing that I was missing? I can't be sure. But I can say if nothing else works, create a new folder and download the project again and run bundle install.. after installing all dependencies / tools first of course, found here -> https://nokogiri.org/tutorials/installing_nokogiri.html

Randall Coding
  • 463
  • 5
  • 15