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
Related
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.
I'm trying to deploy my Rails 4 app on Azure VM running Ubuntu 14.04.
Here's a logfile, atomic fails to install. ruby-v gives me ruby 2.0.0p451
Any ideas how to fix that?
azureuser#my-url:~$ sudo gem install atomic
Building native extensions. This could take a while...
ERROR: Error installing atomic:
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.15 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/atomic-1.1.15/ext/gem_make.out
azureuser#my-url:~$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]
Your gems are using ruby1.9.1 and you are missing dev files.
So install that using this command
sudo apt-get install ruby1.9.1-dev
If you are not sure about your ruby version you can use this command
sudo apt-get install ruby-dev
Make sure you also have the build-essential package installed. You can check using dpkg -l | grep build-essential or simply run sudo apt-get install build-essential.
Personally I tried lots of things before realizing I was missing the above mentioned package.
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.
I'm trying to install rails on ubuntu 12.04 but I'm having some issues
I tried
sudo gem install rails --pre
and got
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
extconf.rb:13:in `require': cannot load such file -- mkmf (LoadError)
from extconf.rb:13:in `<main>'
Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/atomic-1.1.10 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/atomic-1.1.10/ext/gem_make.out
This is because when you installed Ruby you did not install the build tools as well.
I wrote a blog post about installing Ruby + Rails on Ubuntu that has helped out a lot of people, and will probably help you too.
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.
I had a similar problem. It turned out that, even though I had the ~/.rbenv/shims directory at the front of my path, zsh was caching the location of bundle to /usr/local/bin/bundle.
The solution was simply running rehash at the shell (not rbenv rehash). This flushed all the cached commands, including bundle, and all went well after that.
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.