30

After working through the RVM setup, rspec and guard sections of chapter 3 of the Ruby on Rails Tutorial, whenever I run bundle install I get the following error dump:

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:5:in `<main>'


Gem files will remain installed in /home/dan/.bundler/tmp/17577/gems/nokogiri-1.5.2 for inspection.
Results logged to /home/dan/.bundler/tmp/17577/gems/nokogiri-1.5.2/ext/nokogiri/gem_make.out
An error occured while installing nokogiri (1.5.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.5.2'` succeeds before bundling.

In the gem_make.out:

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:5:in `<main>'

I've been debugging for a while now and I think I'm stuck. Help would be GREATLY appreciated!

Dan
  • 3,246
  • 1
  • 32
  • 52
  • Does this help? http://rubyforge.org/forum/forum.php?thread_id=4161&forum_id=4050 – DVG May 05 '12 at 22:49
  • Does bundle install work with nokogiri commented out? – Vidur May 05 '12 at 23:14
  • @VidurMurali: nokogiri is not in my Gemfile, just a dependency and I'm not sure which gem(s) depend on it, so I don't know how I could prevent bundle from trying to install it. – Dan May 05 '12 at 23:20
  • @DVG: I'm not sure if it does. I'm not at all familiar with straight Ruby (or even Rails for that matter) so it's hard to tell if that would work in this situation. – Dan May 05 '12 at 23:20
  • 4
    `sudo aptitude install ruby1.9.1-dev` ? – Zabba May 05 '12 at 23:32
  • @Zabba: Thanks so much! That solved it. If you post an answer I can give you credit... – Dan May 05 '12 at 23:37

1 Answers1

79

You need the header files for compiling extension modules for Ruby.

You can get the proper version for your version of ruby with:

sudo aptitude install ruby-dev

Case
  • 1,848
  • 21
  • 32
Zabba
  • 64,285
  • 47
  • 179
  • 207
  • 5
    It should be worth noting ruby1.9.1 is actually Ruby 1.9.2 – Kris Sep 03 '12 at 13:45
  • 10
    The generic solution is to use `sudo apt-get install ruby-dev`. It will match whatever `ruby` package is in your distribution, assuming you're using Debian/Ubuntu or derivative. – Zenexer Jun 17 '13 at 02:02
  • @Zenexer: Thank you, your answer is actually the solution! – SamFlushing Aug 25 '13 at 10:00