Search code examples
ruby-on-railsrbenv

Replacing RVM with rbenv --mkmf error


I was looking at replacing RVM with rbenv since I am using bundle to manage my gemfiles. rbenv, I believe, is a lot lighter in managing my Ruby versions, so I uninstalled RVM and installed rbenv. I installed the bundler gem using

gem install bundler

because we need it everywhere. Then I opened a project and installed the required version Ruby using rbenv:

rbenv install 1.9.3-p194
rbenv local 1.9.3-p194
rbenv rehash

I entered ruby -v to make sure it was using the right version of Ruby, and it was, so I tried running bundle and it ran until it tried to install RedCloth and and then failed:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby1.9.1 extconf.rb --with-cflags=-w
    /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:1:in `<main>'

It suggested that I install RedCoth before bundling, so I installed RedCloth:

gem install RedCloth

which succeeded. I then ran ruby -v, just to make sure it's still right, then tried running bundle update and the same error occured:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby1.9.1 extconf.rb --with-cflags=-w
    /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:1:in `<main>'

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

I then tried installing a different version of Ruby but had no success there either.

Does anyone have ideas?

I subsequently tried doing the same thing in my other projects and it all seems to work just fine. I have one that uses 1.8.7 and it was as easy as setting the rbenv to the right version and then running bundle. I tried almost every combination of Ruby version and yet it's not working.


Solution

  • I finally overcame the problem.

    I had installed a wrong version of Ruby 1.8.7-p370. I then ran bundle and that had some gems compiling the native extensions against Ruby 1.8.7 when the bundle was for a 1.9.3 package, so even if I was to switch over to the 1.9.3 version and try running bundle again it would bomb out.

    To fix this, I simply removed all the gems and then installed the right version of Ruby and then re-ran bundle.