`require': no such file to load -- mkmf (LoadError)
Ruby on-RailsUbuntuRuby on-Rails Problem Overview
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
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
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.
Solution 2 - Ruby on-Rails
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
Solution 3 - Ruby on-Rails
I also needed build-essential installed:
sudo apt-get install build-essential
Solution 4 - Ruby on-Rails
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...
Solution 5 - Ruby on-Rails
Have you tried:
sudo apt-get install ruby1.8-dev
Solution 6 - Ruby on-Rails
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
Solution 7 - Ruby on-Rails
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.
Solution 8 - Ruby on-Rails
You've Ruby 1.8 so you need to upgrade to at least 1.9 to make it working.
If so, then check https://stackoverflow.com/questions/17026441/how-to-install-a-specific-version-of-a-ruby-gem/24159788#24159788
If this won't help, then reinstalling ruby-dev
again.
Solution 9 - Ruby on-Rails
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)
Solution 10 - Ruby on-Rails
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
- Make sure you have
make
installed git clone
the packagecd
to packagemakepkg
the package
Hope to help! [1]: https://aur.archlinux.org/packages/ruby-nokogiri/