Error installing nokogiri: ERROR: Failed to build gem native extensions

6,512

Solution 1

The key library here was libgmp-dev, installed with:

sudo apt-get install libgmp-dev

possibly due to my use of RVM to manage my ruby versions.

Once done, nokogiri and all the other failing gems were able to be installed (mostl easily just with bundle).

The other gems that had been failing were:

bcrypt-ruby 3.0.1
hitimes 1.2.3
ffi 1.9.10
eventmachine 1.0.7
geoip-c 0.8.1
mysql2 0.3.20

but after the nokogiri install they all installed with bundle

Solution 2

If the above answer doesnt work try this

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

then install Nokogiri

gem install nokogiri
Share:
6,512

Related videos on Youtube

Michael Durrant
Author by

Michael Durrant

rails ruby rspec rock

Updated on September 18, 2022

Comments

  • Michael Durrant
    Michael Durrant over 1 year

    I can build my rails application on my mac

    On my Ubuntu machine when I bundle I get errors with a bunch of gems including nokogiri, version 1.6.7.2

    Error installing nokogiri: ERROR: Failed to build gem native extensions

    I try gem install nokogiri -v1.6.7.2 but I still get the error.

    I am using rvm and ruby 2.3.0

  • Alessio
    Alessio about 8 years
    or you could just install the ruby-nokogiri package (with versions ranging from 1.5.0-1 in precise to 1.6.7.2-3build1 in xenial - see packages.ubuntu.com/… ). bundling code that is available in a distro package is always a bad idea. instead, make a package of your code that depends on other packages....and if a particular ruby gem (or whatever) doesn't exist as a package, make a separate package of that rather than bundle it with your code.
  • Alessio
    Alessio about 8 years
    BTW, ALL of the ruby gems you mention except for geoip-c are available pre-packaged for Ubuntu....and geoip-c's dependencies (minitest and rake) are both available as packages for ubuntu, so building a ruby-geoip-c package should be fairly easy.