Building Gems on Ubuntu

October 11th, 2008 by ScottK | | Filed in ruby

I thought I would just pop in and tell you how on a fresh install of Ubuntu 8.04 I ran into some issues trying to get ruby gems to install. After some research and poking/prodding I’ve come up with the solutions.

Being that this is a fresh install of Ubuntu I did go ahead and apt-get ruby1.8 and rubygems just to kick things off a bit before installing rails and my reguire gems. After the apt-get rubygems install I wanted to update the gems I had by running “sudo gem update –system”. That ran fine.

So now was the time to install rails by using “sudo gem install rails” Big fail as I got an error. “/usr/bin/gem:24: uninitialized constant Gem::GemRunner (NameError)
” Well shit! After some looking it seems that you can add this line to the /usr/bin/gem file: “require ‘rubygems/gem_runner’” after the “require ‘rubygems’”.

require 'rubygems'
# Add the below line
require 'rubygems/gem_runner'

That worked fine for the rails install. However I ran into a new problem. “extconf.rb:1:in `require’: no such file to load — mkmf (LoadError)”. This was easily fixed by “sudo apt-get install ruby1.8-dev”. Seems that some gems require the ruby source files to build. Having them is necessary.

However…

Those that needed the ruby dev started to throw a ton of errors during the “make” portion. It turned out I also needed to “sudo apt-get install g++” as well.

Once I did that all gems installed just fine. So if you have just installed Ubuntu Hardy Haron or are getting any of the three errors then there is what I did. Make sure to edit the /usr/bin/gem file. apt install ruby1.8-dev and g++.

Tags: , ,


3 Responses to “Building Gems on Ubuntu”

  1. deepak kannan | 12/10/08

    it will also be a good idea to install build-essentals

  2. ScottK | 12/10/08

    @deepak thanks for that. I had another machine to format, and yes build-essentials help with the g++ install.

  3. Jeremiah | 22/10/08

    Another thing to watch out for while installing gems in Ubuntu is that sometimes a file that gets added to a directory on $PATH won’t have “#!/usr/bin env ruby” or similar at the top of the file, which leads to some confusing errors.

Share Your Thoughts