Coder Perfect

How to install Rails on Ubuntu with gem


The error message:

Building native extensions.  This could take a while...
ERROR:  Error installing rails:
  ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 -r ./siteconf20150328-1540-hff2f0.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:
/usr/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/lib/ruby/2.1.0/mkmf.rb:571:in `block in try_compile'
  from /usr/lib/ruby/2.1.0/mkmf.rb:522:in `with_werror'
  from /usr/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/lib/ruby/2.1.0/mkmf.rb:621:in `with_cflags'
  from extconf.rb:86:in `add_cflags'
  from extconf.rb:337:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.1.0/gems/nokogiri- for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-


Asked by Allen

Solution #1

I needed to do the following after updating to Rails 4.2.4 on Ubuntu 14.04 using RVM:

sudo apt-get install libgmp-dev


sudo apt-get install libgmp3-dev

Full stacktrace:

Answered by equivalent8

Solution #2

It appears that you are missing a Ruby prerequisite. If you’re using RVM, try these commands:

rvm requirements

to acquire a list of dependencies and manually install them

Otherwise, use the following commands to install the known basic requirements:

sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev autoconf libc6-dev ncurses-dev automake libtool

Answered by shivam

Solution #3

This error occurs because Ruby’s development requirements are lacking.

I suggest that you install and use RVM to solve this, check the official and updated instructions here

When I was answering this question, I took the following steps:

gpg --keyserver hkp:// --recv-keys

\curl -sSL | bash

If you get a warning like this, don’t do anything.

  * WARNING: You have '~/.profile' file, you might want to load it,
    to do that add the following line to '/home/mao/.bash_profile':

  source ~/.profile

execute this command:

echo source ~/.profile >> ~/.bash_profile

Then, by performing this, reload/apply the bash profile that you just updated:

source ~/.bash_profile

Finally, execute this to complete the installation:

rvm requirements

Any Linux distribution should work, including Ubuntu, Fedora, Debian, Redhat, and Slackware.

Answered by Mauricio Gracia Gutierrez

Solution #4

Centos 7 and Redhat 7:

yum -y install gcc ruby-dev

Answered by Abdennour TOUMI

Post is based on