14

I've been googling this error below, but I can't solve this error:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /home/dyego/.bundler/tmp/9200/gems/sqlite3-1.3.9 for inspection.
Results logged to /home/dyego/.bundler/tmp/9200/extensions/x86_64-linux/2.1.0/sqlite3-1.3.9/gem_make.out
An error occurred while installing sqlite3 (1.3.9), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.9'` succeeds before bundling.
         run  bundle exec spring binstub --all
/usr/lib/ruby/vendor_ruby/bundler/resolver.rb:296:in `resolve': Could not find gem 'sqlite3 (>= 0) ruby' in the gems available on this machine. (Bundler::GemNotFound)
    from /usr/lib/ruby/vendor_ruby/bundler/resolver.rb:168:in `start'
    from /usr/lib/ruby/vendor_ruby/bundler/resolver.rb:129:in `block in resolve'
    from /usr/lib/ruby/vendor_ruby/bundler/resolver.rb:128:in `catch'
    from /usr/lib/ruby/vendor_ruby/bundler/resolver.rb:128:in `resolve'
    from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:179:in `resolve'
    from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:114:in `specs'
    from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:159:in `specs_for'
    from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:148:in `requested_specs'
    from /usr/lib/ruby/vendor_ruby/bundler/environment.rb:18:in `requested_specs'
    from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:13:in `setup'
    from /usr/lib/ruby/vendor_ruby/bundler.rb:120:in `setup'
    from /usr/lib/ruby/vendor_ruby/bundler/setup.rb:17:in `<top (required)>'
    from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'

So I googled this error:

mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

and I got some similar questions like this one: Error while installing json gem 'mkmf.rb can't find header files for ruby'

But I already installed ruby-dev:

sudo apt-get install ruby-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ruby-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 72 not upgraded.

I'm really struggling to solve this problem (even though it seems to be a simple one).

Community
  • 1
  • 1
user309838
  • 337
  • 1
  • 2
  • 13

2 Answers2

39

Try to install the ruby-dev library for your Ruby version which is 2.1

$ sudo apt-get install ruby2.1-dev
Alireza
  • 2,641
  • 17
  • 18
  • 2
    If you're lazy and it's not a production system, just installing `ruby-dev` also does the trick. And yes, I realize it's amusing that I'm putting more effort into this comment than it would've taken for me to type the extra 3 characters necessary for version specificity. I blame society. – Parthian Shot Aug 12 '15 at 01:06
  • 1
    By now it should be `ruby-2.3-dev`. You can figure out the package name by running ` apt-cache search "ruby.*-dev"` if you're on a Debian-based distribution (e.g. Ubuntu, Mint). – einpoklum Jan 28 '17 at 13:07
3

Had similar error on fedora when trying to install compass for SASS development

gem install compass

failed with

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

/usr/bin/ruby extconf.rb mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h

Ran this

yum -y install gcc ruby-devel rubygems 

and then was able to run the install again successfully.

Shaun O'Hagan
  • 191
  • 1
  • 5
  • I get `No package ruby-devel available.` when executing `yum -y install ruby-devel`. Is there a newer package to install? – Jack Straw Jan 14 '16 at 00:17
  • This is the answer that helped me when I was trying to install compass. However, rubygems wasn't necessary. I just used sudo yum install ruby-devel gcc -y – GTS Joe Jun 16 '16 at 04:11