`require': no such file to load -- mkmf (LoadError)
Asked Answered
P

10

570

I was trying to install rails on Ubuntu Natty Narwhal 11.04, using ruby1.9.1.

I installed ruby using apt-get install ruby1.9.1-full which contains the dev package. I googled the error and all have suggested I install the 1.9.1-dev which I already have.

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

        /usr/bin/ruby1.8 extconf.rb
extconf.rb:36:in `require': no such file to load -- mkmf (LoadError)
    from extconf.rb:36


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out
Pennyworth answered 4/10, 2011 at 9:39 Comment(2)
I had a parallel error attempting to install watir-webdriver. It also was corrected by installing ruby1.0.1-devGrunenwald
possible duplicate of Rails installation failed on Ubuntu with "cannot load such file -- mkmf"Farlay
K
981

After some search for a solution it turns out the -dev package is needed, not just ruby1.8. So if you have ruby1.9.1 doing

sudo apt-get install ruby1.9.1-dev

or to install generic ruby version, use (as per @lamplightdev comment):

sudo apt-get install ruby-dev

should fix it.

Try locate mkmf to see if the file is actually there.

Kneel answered 13/11, 2011 at 17:9 Comment(6)
the following will install the dev package matched to your currently installed ruby version: sudo apt-get install ruby-devGoodill
yeah worked for me. run ruby -v to find the version if you only want to install the current ruby version.Anthesis
@Goodill Didnt work for me, ruby version was 1.9.3 and it was installing 1.8 If I tried to install ruby-devHotien
I've installed ruby-all-dev, it will probably work for all versions.Drusy
This is also required for aws-sdk now that SOAP is deprecated for AWS. A worry if stakeholders object to anything -dev on a production build. (SDK's don't thrill them either).Woundwort
Saved me on 2024 with ruby-devEisk
M
186

This is the answer that worked for me. Was in the comments above, but deserves its rightful place as answer for ubuntu 12.04 ruby 1.8.7

sudo apt-get install ruby-dev
# if above doesnt work make sure you have build essential
sudo apt-get install build-essential
Mattox answered 9/5, 2013 at 4:17 Comment(3)
It's also worth noting that if you want to use the ubuntu software center there is an add-on for ruby-dev you can select for the 'Header files for compiling extension modules'.Undercroft
I used sudo apt-get install ruby1.9.1-dev with ruby 1.9.3 before I saw the comment or this answer, and that allowed me to build the rails extension. Not sure if mismatching versions like that is going to cause me any headache later, but it should be noted that rails installed correctly using a slight alteration of the officially accepted answer.Fafnir
What if you have RVM? Then don't you already have the ruby version you need?Anteater
O
37

I also needed build-essential installed:

sudo apt-get install build-essential
Oza answered 1/7, 2013 at 11:42 Comment(1)
This was the ticket right here.. I imagine I had to also install ruby-dev but it didn't work until I installed build-essential as well. a million thanksCymograph
M
30

The problem is still is recursive on Ubuntu 13/04/13.10/14.04

and

sudo apt-get install ruby1.9.1-dev

worked out for me okay. So If you are using Ubuntu 13.04/13.10/14.04 then using this will really come in handy.

This works even if ruby version is 1.9.3. This is because there is no ruby1.9.3-dev available in the Repository...

Mertens answered 23/11, 2013 at 9:29 Comment(2)
Yep, this one worked for me as well on ruby1.9.3. There wasn't a package in the ubuntu repository for ruby1.9.3-dev.Fafnir
not any more... worked after installing rvm from rvm.io with --ruby - and probably best to apt-get remove ruby beforeSolenoid
S
18

Have you tried:

sudo apt-get install ruby1.8-dev
Sternforemost answered 4/10, 2011 at 9:44 Comment(3)
I'm using 1.9.1, why shall I install ruby1.8-dev ?Pennyworth
This is so weird indeed I installed 1.9.1 but it reads 1.8, when I run ruby -v I get: ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]Pennyworth
you have ruby 1.8 set as default ruby on your systemSternforemost
S
10

I got the similar error when install bundle

sudo apt-get install ruby-dev

Works great for me and solve the problem Mint 16 ruby1.9.3

Studnia answered 15/1, 2014 at 12:41 Comment(0)
L
2

I think is a little late but

sudo yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel

worked for me on fedora.

http://nokogiri.org/tutorials/installing_nokogiri.html

Lisandralisbeth answered 12/12, 2013 at 4:51 Comment(0)
M
1

You've Ruby 1.8 so you need to upgrade to at least 1.9 to make it working.

If so, then check How to install a specific version of a ruby gem?

If this won't help, then reinstalling ruby-dev again.

Methylal answered 11/6, 2014 at 9:48 Comment(0)
H
0

You can use RVM(Ruby version manager) which helps in managing all versions of ruby on your machine , which is very helpful for you development (when migrating to unstable release to stable release )

or for Linux (ubuntu) go for sudo apt-get install ruby1.8-dev

then sudo gem install rails to verify it do rails -v it will show version on rails

after that you can install bundles (required gems for development)

Hymnist answered 19/11, 2012 at 7:31 Comment(1)
You can still use RVM on linux. I am doing that (but still have the issue of this mkmf error when installing rails)Anteater
G
0

Ruby version: 2.7.1 gem version: 3.1.3

You need to check the extension that could not be installed, and find the reasons.

Read the mkmf.log file showed at the installation error under "To see why this extension failed to compile, please check the mkmf.log which can be found here" , perhaps there is a missing lib ( sometimes iconv ), and you must install it.

You can search the extension with your package manager(apt, yum, pacman...) too.

(Personal case) Arch Linux->nokogiri

gem install rails

Showed me:

To see why this extension failed to compile, please check the mkmf.log which can be found here: /home/user/.gem/ruby/2.7.0/extensions/x86_64-linux/2.7.0/nokogiri-1.10.9/mkmf.log

Go to: https://aur.archlinux.org/packages/ruby-nokogiri/

  1. Make sure you have all dependencies installed
  2. Make sure you have make installed
  3. git clone the package
  4. cd to package
  5. makepkg the package

Hope to help!

Goforth answered 17/6, 2020 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.