dominikduda
dominikduda

Reputation: 335

Installing rails on ubuntu - ERROR: Failed to build gem native extension

I wanted to start learning ror, but I have problem installing it. Thats what my console says when I type "sudo gem install rails" in.

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

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:1:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.8.3 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.8.3/ext/json/ext/generator/gem_make.out

This solved problem:

sudo apt-get install ruby-dev

Upvotes: 2

Views: 7195

Answers (2)

James B. Byrne
James B. Byrne

Reputation: 1064

You need a more recent version of Ruby to start with if you are using the latest version of Rails.

Ruby on Rails 4.0 Release Notes

Highlights in Rails 4.0:

Ruby 2.0 preferred; 1.9.3+ required

Whereas in your error message we see:

/usr/bin/ruby1.9.1 . . .

And, in future you should always include in your question the version numbers of all of the software components involved with your problem. It makes focusing on the real issue much simpler for people looking to help you.

Upvotes: 0

Jai Kumar Rajput
Jai Kumar Rajput

Reputation: 4217

References : http://railsapps.github.io/installrubyonrails-ubuntu.html

Prepare Your System

You’ll need to prepare your computer with the required system software before installing Ruby on Rails.

You’ll need superuser (root) access to update the system software.

Update your package manager first:

$ sudo apt-get update

This must finish without error or the following step will fail.

Install Curl:

$ sudo apt-get install curl

You’ll use Curl for installing RVM. Install Ruby Using RVM

Use RVM, the Ruby Version Manager, to install Ruby and manage your Rails versions.

If you have an older version of Ruby installed on your computer, there’s no need to remove it. RVM will leave your “system Ruby” untouched and use your shell to intercept any calls to Ruby. Any older Ruby versions will remain on your system and the RVM version will take precedence.

Ruby 2.3.0 was current when this was written. You can check for the current recommended version of Ruby. RVM will install the newest stable Ruby version.

The RVM website explains how to install RVM. Here’s the simplest way:

$ \curl -L https://get.rvm.io | bash -s stable --ruby

Note the backslash before “curl” (this avoids potential version conflicts).

The “—ruby” flag will install the newest version of Ruby.

RVM includes an “autolibs” option to identify and install system software needed for your operating system. See the article RVM Autolibs: Automatic Dependency Handling and Ruby 2.0 for more information. If You Already Have RVM Installed

If you already have RVM installed, update it to the latest version and install Ruby:

$ rvm get stable --autolibs=enable
$ rvm install ruby
$ rvm --default use ruby-2.3.0

Installation Troubleshooting and Advice RVM Troubleshooting

If you have trouble installing Ruby with RVM, you can get help directly from the RVM team using the IRC (Internet Relay Chat) channel #rvm on irc.freenode.net:

http://webchat.freenode.net/?channels=rvm

If you’ve never used IRC, it’s worthwhile to figure out how to use IRC because the RVM team is helpful and friendly. IRC on freenode requires registration (see how to register).

Upvotes: 2

Related Questions