cannot load such file -- mkmf (LoadError) - ruby-on-rails

Using rbenv, runnng bundle install, and getting an error installing Json 1.8.1.
Building native extensions. This could take a while...
ERROR: Error installing json:
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:1:in `<main>'
Tried installing ruby-dev via apt (not sure that will help anyway, as ruby was installed via rbenv)
stuff that may help?
$ which gem
/home/ubuntu/.rbenv/shims/gem
$ which ruby
/home/ubuntu/.rbenv/shims/ruby
$ locate mkmf
/home/ubuntu/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/mkmf.rb
/home/ubuntu/.rbenv/versions/1.9.3-p484/share/ri/1.9.1/system/Object/mkmf-i.ri
/usr/local/rvm/gems/ruby-2.2.1/extensions/x86_64-linux/2.2.0/nokogiri-1.6.6.2/mkmf.log
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb

Based on your locate command, you have mkmf in rvm and in ubuntu's home diretory, but not on the system, and you're explicitly using the system's ruby (and not rbenv or rvm) to run the extconf.rb. Either run a ruby from one of the environments you have mkmf in, or install the ruby-dev package on the system.

Related

Error when installing the CarrierWave gem for rails

I am attempting to install the CarrierWave gem for my Ruby on Rails application. When I go to the command prompt and type sudo gem install carrierwave I get the following error:
Building native extensions. This could take a while...
ERROR: Error installing carrierwave:
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:13:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/atomic-1.1.13 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/atomic-1.1.13/ext/gem_make.out
What on earth does this mean and how do I fix it?
Thanks, any help appreciated.
Lots of advice here: `require': no such file to load -- mkmf (LoadError)
It general, it sounds like you probably need to install some build tools.

Failed to build gem native extension (mkmf (LoadError)) - Ubuntu 12.04 [duplicate]

This question already has answers here:
Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)
(17 answers)
Closed 9 years ago.
Hey I'm trying to install rails on a new ubuntu machine. I have ruby and rvm installed but I'm getting a "failed to build gem native extension" error. What does this mean?
$ sudo gem install rails -v 3.2.9
(without the sudo says I don't have permissions)
Then it outputs a lot of 'fetching' commands and ultimately this error:
Building native extensions. This could take a while...
ERROR: Error installing rails:
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:1:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.8.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.8.0/ext/json/ext/generator/gem_make.out
When I type
$rails server
It says rails is not currently installed
Possible duplicate of:
Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)
Depending on your ruby version, run:
sudo apt-get install ruby1.9.1-dev
If you are using RVM, you shouldn't ever be using 'sudo'. Using sudo calls libs and such out of the rvm path. Try just a flat:
gem install rails -v3.2.9
and see if that helps.

Rails 3, error installing pg gem

Tried to install pg gem I got the next error:
alex#ubuntu:~/RubymineProjects/Tiger Skills$ gem install pg
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.9.1 directory.
alex#ubuntu:~/RubymineProjects/Tiger Skills$ sudo gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
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:2:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/pg-0.15.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/pg-0.15.1/ext/gem_make.out
gem_make.out file:
/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:2:in `<main>'
Already tryed to solve using
$ sudo apt-get install postgresql-client libpq5 libpq-dev
then:
$ sudo gem install pg
That is because you have not set the write permission to the directory,try:
chmod +777 /var/lib/gems/1.9.1
You need to install the -dev part of the Ruby package. Something like:
sudo apt-get install ruby1.9-dev
should give you the parts of Ruby necessary to compile binary extensions.
Good luck!
This help me:
sudo apt-get install rails
I got almost the same problem.
I use this to solve it.
$rvmsudo gem install pg

Trying to install Rails, Failed to Build Gem Native Extension

I'm trying to install Rails on Ubuntu 12.10 using the Ruby Version Manager. I believe that Ruby and RubyGems are installed correctly, and these are my versions:
ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
gem -v: 1.8.23
I'm trying to install rails, using
sudo gem install rails -v 3.2.9
This fetches a lot of gems, but has a problem building the native extensions:
Building native extensions. This could take a while...
ERROR: Error installing rails:
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:1:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.7.5 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.7.5/ext/json/ext/generator/gem_make.out
Any idea what I'm doing wrong? If it helps, I'm trying to follow the tutorial at http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-install_rails.
Thank you!
Install the gem as a normal user, not sudo:
gem install rails
Or install the ruby dev package. There are a lot of similar answers in SO:
Failed to build gem native extension — Rails install
Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)
Do you have a C compiler installed? If not, you should run sudo apt-get install build-essential to set up a compiler toolchain

Why do I get an error installing the JSON gem in Ubuntu?

Using Ubuntu, when I run "bundle install" to set up my Rails environment, it throws an error during the JSON gem installation:
Installing json (1.7.3) 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:1:in `<main>'
Gem files will remain installed in /home/danny/.bundler/tmp/2040/gems/json-1.7.3 for inspection.
Results logged to /home/danny/.bundler/tmp/2040/gems/json-1.7.3/ext/json/ext/parser/gem_make.out
An error occured while installing json (1.7.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.3'` succeeds before bundling.
When I try installing only the JSON 1.7.3 gem it also gives me an error:
Building native extensions. This could take a while...
ERROR: Error installing json:
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:1:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.7.3 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.7.3/ext/json/ext/parser/gem_make.out
I've installed RVM and am running Ruby 1.9.3; Why can't it install the JSON gem?
Installing the ruby1.9.1-dev package should fix this for you:
sudo apt-get install ruby1.9.1-dev

Resources