Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)
Asked Answered
K

17

210

Ruby 1.9.3

The part of Gemfile

#...............
gem "pony"
gem "bcrypt-ruby", :require => "bcrypt"
gem "nokogiri" 
#..................

When I'm trying to install gems, I get an error

alex@ubuntu:~/$ bundle
Fetching gem metadata from http://rubygems.org/.........
Fetching gem metadata from http://rubygems.org/..
Enter your password to install the bundled RubyGems to your system: 
#####............................................................
Installing bcrypt-ruby (3.0.1) with native extensions 
Gem::Installer::ExtensionBuildError: 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:36:in `<main>'


Gem files will remain installed in /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out
An error occurred while installing bcrypt-ruby (3.0.1), and Bundler cannot continue.
Make sure that `gem install bcrypt-ruby -v '3.0.1'` succeeds before bundling.

Then I'm doing this

sudo gem install bcrypt-ruby -v '3.0.1'
Building native extensions.  This could take a while...
ERROR:  Error installing bcrypt-ruby:
        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:36:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out

and getting an error as well.

What did I miss?

Kellner answered 7/12, 2012 at 17:8 Comment(2)
possible duplicate of `require': no such file to load -- mkmf (LoadError)Selfreliant
For macOS, this might be helpful as well: #20940068Unbiased
F
474

There are similar questions:

Usually, the solution is:

sudo apt-get install ruby-dev

Or, if that doesn't work, depending on your ruby version, run something like:

sudo apt-get install ruby1.9.1-dev

Should fix your problem.


Still not working? Try the following after installing ruby-dev:

sudo apt-get install make
Flannery answered 7/12, 2012 at 17:13 Comment(9)
But I have 1.9.3 ruby only.Kellner
ruby 1.9.3 is an alias of ruby 1.9.1Matzo
After installing ruby1.9.1-dev I had to also sudo apt-get install make. Thank you!Polacre
If you have installed your ruby with command sudo apt-get install ruby (without specifying the version) then you don't need to worry about your version too much if you just install sudo apt-get install ruby-devAsphodel
Thank you @wasatchwizard, after doing what you suggested it worked for me :)Thirtieth
Worked for me, thanks. But I did end up running bundle install as sudo.Basement
Thanks - using sudo apt-get install make finally did the trick for me, after I found the first part of your solution elsewhere.Blond
I found that on Ubuntu 16.04 you also need sudo apt-get install gcc makeTellus
I am getting this error: sudo: apt-get: command not found can I install it with brew ?Stock
G
31

For WSL (Windows Subsystem for Linux) you need install build-essential package:

sudo apt install build-essential
Garderobe answered 25/4, 2019 at 18:10 Comment(5)
Solved it for me after none of the other suggestions seemed to do it. My setup: Win10 Pro + WSL with Ubuntu 18.04 + Ruby 2.5. Thanks!Pearliepearline
Same thing for an Ubuntu Server Hyper-V VM.Tipperary
Worked for me on Ubuntu within DockerPhotometry
This worked for me on a regular install of Ubuntu 18.04 LTS when trying to install Typhoeus. Took ages to get there, thanks!Glacis
im not a ruby guy so im totally mystified as to why this is required to install a simple gem, but im thankful for this answer. was exactly the issue for meSeizing
G
15

For MacOS users:

Just do this and easily it will solve your problem:

brew install cocoapods
Godly answered 22/1, 2021 at 4:1 Comment(0)
F
12

Just finished a 2 hour wild goose chase trying to solve this. None of the posted answers worked for me. Im on a Mac (Mojave Version 10.14.6, Xcode Version 11.3).

It turns out the ruby file headers were missing so i had to run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

That didnt work for me at first because the version of CommandLineTools i had installed did not have the "Packages" folder. So i uninstalled and reinstalled like this:

rm -rf /Library/Developer/CommandLineTools

xcode-select --install

Then i ran the previous command again:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

After install the error was fixed!

Filtration answered 12/12, 2019 at 15:25 Comment(3)
This worked for me. I'm on macOS 10.14.6 (18G1012). Xcode 11.3.Louden
Thanks. Your solution worked for me when installing "sudo gem install cocoapods" for flutter development.Twinberry
I don't get 'Packages/' folder after reinstalling.Apriorism
O
10

I had the same issue trying to install jquery-rails. The fix was

sudo apt-get install zlibc zlib1g zlib1g-dev
Ossieossietzky answered 11/11, 2015 at 4:31 Comment(1)
Just installing zlib1g-dev will give you what you need here, or at least it did for me.Dissident
G
7

In case anyone in the future had this problem, I'm using a Mac and just had to install the Command Line Tools using 'xcode-select --install'

Gout answered 11/7, 2015 at 22:32 Comment(1)
This worked for me. In my case, I was scratching my head because my build was working fine until I upgraded to El Capitan.Higgins
M
6

I found that I needed to install another version of ruby. So running the command

$ sudo apt-get install ruby1.9.1-dev

and then attempt to install the extension

If you run into issues where it is telling you that you don't have g++ you can run the following command to install it

$ sudo apt-get install g++
Mccallum answered 19/11, 2015 at 9:18 Comment(0)
L
5
  1. Make sure ruby-dev is installed
  2. Make sure make is installed
  3. If you still get the error, look for suggested packages. If you are trying to install something like gem install pg you will also need to install the lib libpq-dev (sudo apt-get install libpq-dev).
Lipkin answered 29/5, 2015 at 5:21 Comment(0)
S
5

I created a small hackMD to install cocoapods on MacOS 10.15 (Catalina) and 11 (Big Sur)

https://hackmd.io/@sBJPlhRESGqCKCqV8ZjP1A/S1UY3W7HP

Installing Cocoapods on MacOS Catalina(MacOS 10.15.X) and Big Sur (MacOS 11)

  1. Make sure you have xcode components are installed.

  2. Download 'Command Line Tools' (about 500MB) directly from this link (Requires you to have apple account) https://developer.apple.com/downloads/index.action

  3. Install the downloaded file

  4. Click on Install

  5. Install COCOAPODS files in terminal sudo gem install -n /usr/local/bin cocoapods

Sibley answered 19/9, 2020 at 5:9 Comment(1)
brew install cocoapods worked for me (assuming you have brew installed and up to date)Sweltering
L
2

This worked for me. bundle config --global build.snappy --with-opt-dir="$(brew --prefix snappy)"

Lizliza answered 8/5, 2020 at 18:16 Comment(0)
P
1

It also helps to ensure libmysqlclient-dev is installed (Ubuntu 14.04)

Prescott answered 10/12, 2015 at 21:45 Comment(0)
C
1

What ended up working for me after a few hours of pain..

if you're running brew..

brew install ruby

in the terminal output/log, identify the path where ruby was installed, brew suggests 'You may want to add this to your PATH', so that's what we'll do. For example, mine is

/usr/local/lib/ruby/gems/3.0.0/bin

Add this to your path by running (omitting braces)

echo 'export PATH"{the_path_you_found_above}:$PATH"' >> ~/.bash_profile

then update your environment by running

source ~/.bash_profile

now, try running your install, i.e.,

sudo gem install middleman
Cowshed answered 22/1, 2021 at 7:9 Comment(0)
S
1

If you are a mac user you must need to update the clang version being used I burnt hours searching this and installed uninstalled xcode commandline tools but it didn't help. I ran gcc -v and Apple clang version 11.0.0 (clang-1100.0.33.8 was the output. Then I ran xcode-select -s /Library/Developer/CommandLineTools/ and clang version was updated to Apple clang version 12.0.0 (clang-1200.0.32.29). bundle install was successful after that. I hope this may help.

Silden answered 3/3, 2021 at 23:35 Comment(0)
W
1

I was making a word search app and I had to install cocoapods and after formatting my mac and reinstalling xcode, I still got the error when I wanted to install cocoapods.

And the solution for this was the following:

It looks like CocoaPods 1.9.0, the latest version as of this writing, depends on a newer version of Ruby than 2.3.7. But macOS Mojave only includes Ruby 2.3.7, so you have a few different options.

    Upgrade to macOS Catalina and get Ruby 2.6.3
    Use Ruby Version Manager to install a newer version of Ruby
    Install an older version of CocoaPods
    sudo gem install cocoapods -v 1.8.4

I did 3:

sudo gem install cocoapods -v 1.8.4

Ward answered 22/4, 2021 at 22:46 Comment(0)
H
1

first set your Xcode version on the terminal:

sudo xcode-select -switch /Applications/Xcode.app

then install:

sudo gem install cocoapods
Hesson answered 1/8, 2022 at 8:50 Comment(1)
It works for me on Macbook m1 pro Sonoma 14.0Largehearted
G
0

In Mac, for me this works:

CONFIGURE_OPTS="--enable-shared" rbenv install 2.2.2
Gemperle answered 19/8, 2016 at 8:24 Comment(0)
S
0

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 to locate mkmf to see if the file is actually there.

Sulphathiazole answered 1/8, 2017 at 10:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.