74

I have been installing Ruby on Rails based on the instruction from edX online class.

Here is a list of terminal commands, and, where relevant, corresponding output:

$ sudo apt-get install ruby1.9.1

installation successful

$ wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz
$ tar zxvf ruby-1.8.24.tgz
$ cd ruby-1..8.24
$ sudo ruby setup.rb
RubyGems 1.8.24 installed

== 1.8.24 / 2012-04-27

* 1 bug fix:

  * Install the .pem files properly. Fixes #320
  * Remove OpenSSL dependency from the http code path


------------------------------------------------------------------------------

RubyGems installed the following executables:
    /usr/bin/gem1.9.1

Up to here, everything looked fine, but the I tried to install rails and failed:

$ sudo gem install rails
Fetching: i18n-0.6.1.gem (100%)
Fetching: multi_json-1.3.6.gem (100%)
Fetching: activesupport-3.2.8.gem (100%)
Fetching: builder-3.0.3.gem (100%)
Fetching: activemodel-3.2.8.gem (100%)
Fetching: rack-1.4.1.gem (100%)
Fetching: rack-cache-1.2.gem (100%)
Fetching: rack-test-0.6.1.gem (100%)
Fetching: journey-1.0.4.gem (100%)
Fetching: hike-1.2.1.gem (100%)
Fetching: tilt-1.3.3.gem (100%)
Fetching: sprockets-2.1.3.gem (100%)
Fetching: erubis-2.7.0.gem (100%)
Fetching: actionpack-3.2.8.gem (100%)
Fetching: arel-3.0.2.gem (100%)
Fetching: tzinfo-0.3.33.gem (100%)
Fetching: activerecord-3.2.8.gem (100%)
Fetching: activeresource-3.2.8.gem (100%)
Fetching: mime-types-1.19.gem (100%)
Fetching: polyglot-0.3.3.gem (100%)
Fetching: treetop-1.4.10.gem (100%)
Fetching: mail-2.4.4.gem (100%)
Fetching: actionmailer-3.2.8.gem (100%)
Fetching: rake-0.9.2.2.gem (100%)
Fetching: rack-ssl-1.3.2.gem (100%)
Fetching: thor-0.16.0.gem (100%)
Fetching: json-1.7.5.gem (100%)
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/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:1:in `<main>'


Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/json-1.7.5 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/json-1.7.5/ext/json/ext/generator/gem_make.out
Ry-
  • 218,210
  • 55
  • 464
  • 476
pata kusik
  • 872
  • 1
  • 7
  • 10
  • possible duplicate of [Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)](http://stackoverflow.com/questions/13767725/unable-to-install-gem-failed-to-build-gem-native-extension-cannot-load-such) – David Waters Dec 17 '14 at 20:44

3 Answers3

161

mkmf is part of the ruby1.9.1-dev package. This package contains the header files needed for extension libraries for Ruby 1.9.1. You need to install the ruby1.9.1-dev package by doing:

sudo apt-get install ruby1.9.1-dev

Then you can install Rails as per normal.

Generally it's easier to just do:

sudo apt-get install ruby-dev
markus
  • 40,136
  • 23
  • 97
  • 142
Suhail Patel
  • 13,644
  • 2
  • 44
  • 49
  • had to write `sudo apt-get install ruby1.9.1-dev` instead of `sudo apt-get install ruby1.9-dev`. Otherwise worked just fine, thanks. – pata kusik Sep 23 '12 at 14:10
  • Thanks a lot dude! I's getting nuts with rb-inotify dependency issue... (with sass -watch) – jossemarGT Mar 29 '13 at 02:34
  • 17
    For the record, `sudo apt-get install ruby-dev` was enough for me. – ezakto Oct 07 '14 at 19:55
  • Again, thanks. I was trying to set up the gh-pages gem on ubuntu following these instructions: https://help.github.com/articles/using-jekyll-with-pages/ , I must have missed the install ruby-dev step though. – davewasthere Nov 03 '14 at 05:45
  • Yes.In my computer,this version is ruby.v.2.1,and if I have installed the ruby1.9.1-dev,the result has error yet. If I use `sudo apt-get install ruby-dev`,the ubuntu will install the ruby2.1-dev,So the result is OK! – bnPYSse Nov 06 '14 at 14:24
  • I did `sudo apt-get install ruby-all-dev` – Robin Winslow Jan 11 '15 at 17:28
  • Hello guys I am getting this error. *sudo: apt-get: command not found* can I install ruby-dev with brew ? – GOrozco58 May 04 '17 at 21:54
8

The suggested answer only works for certain versions of ruby. Some commenters suggest using ruby-dev; that didn't work for me either.

sudo apt-get install ruby-all-dev

worked for me.

user1821237
  • 89
  • 1
  • 2
5
sudo apt-get install ruby-dev

worked for me

Tanzeel
  • 455
  • 6
  • 16