CNK's Blog

Ubuntu 12.04 on VirtualBox 4.2

I got a call today from someone who had upgraded their desktop from Ubuntu 8 to Ubuntu 12 and was having trouble getting Ruby reinstalled. She had previously installed Ruby from source (as apparently everyone needs to do in the Debian/Ubuntu world) without any problem - but not this time. I do a reasonable amount of Ruby and system administration but I work in a RedHat shop so don’t know a ton about Debian-derived distros. But I thought I would try to see what I could do to help.

Installing Ubuntu 12.04

First thing I need is an Ubuntu box to practice on. I had VirtualBox installed and have used Vagrant to manage some boxes. However, since Vagrant is written in Ruby and usually does its configuration of the box with Chef or Puppet, I think the premade vagrant images will already have Ruby installed. - making it difficult to figure out the correct steps for installing Ruby from source. So I think I should install Ubuntu without my favorite virtualization tool.

First, I upgraded my VirtualBox software to 4.2.4. (My older boxes appear to still run but they appear to have lost their Guest Additions; I’ll have to go back and sort that out).

Ubuntu is pretty common so I searched for a prebuilt (hopefully minimal) VirtualBox image and found a promising looking one at http://virtualboxes.org/images/ubuntu/. I downloaded this one:

    Ubuntu Linux 12.04 x86
    Size (compressed/uncompressed): 769 MB/3.2 GB
    Link: http://sourceforge.net/projects/virtualboximage/files/Ubuntu%20Linux/12.04/ubuntu_12.04-x86.7z
    Active user account(s) (username/password): ubuntu/reverse
    Notes: Guest Additions NOTinstalled; tip: set Video RAM 64MB minimum

First issue: that is compressed with 7zip so I’ll need p7zip to uncompress it. Fortunately I have Homebrew installed so I just did:

    $ brew install 7zip

This installed a formula it said was p7zip from https://github.com/mxcl/homebrew/commits/master/Library/Formula/p7zip.rb and brew list p7zip shows:

    $ brew list p7zip
    /usr/local/Cellar/p7zip/9.20.1/bin/7zr
    /usr/local/Cellar/p7zip/9.20.1/bin/7za
    /usr/local/Cellar/p7zip/9.20.1/bin/7z
    /usr/local/Cellar/p7zip/9.20.1/lib/p7zip/ (6 files)
    /usr/local/Cellar/p7zip/9.20.1/share/doc/ (50 files)
    /usr/local/Cellar/p7zip/9.20.1/share/man/ (3 files)

After a little fishing around I think the uncompress command is ‘7z x '

    $ man 7z
    $ 7z x Downloads/ubuntu_12.04-x86.7z
    Extracting  ubuntu_12.04/ubuntu_12.04.vbox

This produces a folder named ubuntu_12.04 containing a small .vbox file and 3.5 GB .vdi file. The later is the ‘virtual disk image’ file that we will want to use to create our new VM. I followed [these instructions] (http://www.thelinuxdaily.com/2010/02/how-to-setup-a-pre-built-virtualbox-guest-image-tutorialguide/) and created a new VM with 512 MB RAM and using the pre-existing .vdi file. Then I just start the newly created VM from the menu.

There are a couple of peculiarities - the main one is that the requested keyboard is Italian. I found the keyboard settings and chose an English keyboard layout instead. Then I changed the update server to the server for the US and upgraded packages. The GUI says it wants to do 489 updates!

VirtualBox Guest Additions

Oh, and I don’t need the Guest Additions for preventing the VirtualBox from capturing my mouse but I do need them so I can cut and paste between the host and guest OSs. Under the VirtualBox Devices menu there is an item for Install Guest Additions. Clicked that to get them installed. However even though I rebooted the virtual machine, I still can’t copy and paste between the VM to my Mac.

Installing Ruby

OK now for installing Ruby. The person I am helping was installing Ruby globally from source but I wanted to see if RVM could install Ruby 1.8.7 for me. First I installed rvm:

    $ curl -L https://get.rvm.io | bash

That added a .bash_profile to my home directory. That didn’t play well with my shell in emacs so I moved that line to my .bashrc file. Then I installed ruby and made it my default ruby:

    $ rvm install 1.8.7
    $ rvm use --default 1.8.7

That worked just fine - but I can’t install any gems.

    $ gem install bundler
    ERROR: Loading command: install (LoadError)
           no such file to load -- zlib
    ERROR: While executing gem ... (NameError)
           uninitialized constant Gem::Commands::InstallCommand

Sounds like I am missing some dependencies. Fortunately RVM will tell me what it needs - and in Ubuntu syntax:

    $ rvm requirements
    $ sudo apt-get install build-essential openssl libreadline6
         libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev
         libyaml-dev libsql3-dev sqlite3 libxml2-dev libxslt-dev
         autoconf libc6-dev ncurses-dev automake libtool bison
         subversion pkg-config

However, once I installed those, I still wasn’t able to install any gems. Apparently I should have installed the prerequisites BEFORE I installed the ruby. Once I got the order correct, installing ruby 1.8.7 via RVM also installed 4 gems:

    bundler
    rake
    rubygems-bundler
    rvm