Up and Running with VB/Ubuntu

Setup struggles and successes


There’s a saying in Hebrew that applies really well to what I spent the last 24 hours doing. “Kol hatchalot kashot.” All beginnings are difficult.

It’s been a while since I’ve done something on a computer that left me feeling as totally out of my element as trying to get up and running with a new VB/Ubuntu/RoR setup. Since I’ve committed to documenting my journey from industrial engineer to full-stack developer, I decided to take notes on my setup process.

Maybe this will be helpful to someone else looking to get started.
Or maybe this will just serve as an ever-lasting testament to how clueless I was when I first started this crazy ride.

In any case, here’s how it went.

I have a Windows 7 machine. While this has been fine for things like Codecademy, I’ve heard nightmare stories about using Windows for Ruby on Rails development in the long run. Gems not installing properly, code incompatibilities, and a whole list of stuff that I don’t know enough about yet to know the significance of. Keeping that in mind, I decided now would be a great time to get to know Linux a little bit, so the first step (since I’m not at all tempted to switch my entire machine’s OS) was to get a virtual machine set up. I’ll save the RoR setup for a different post.

1) Install VirtualBox

VirtualBox is a free tool from Oracle to setup and manage virtual machines on your computer. The downloads page is here. The installation on my Windows machine seemed pretty simple… until I tried opening the program after installation.

 Failed to verify process integrity: Unknown image file \Device\HarddiskVolume2\PROGRA~2\Sophos\SOPHOS~1\SOPHOS~2.DLL at 0000000075650000. 

Not really what I was hoping for. Sophos is an antivirus program that my old work installed on this computer before letting me remote in. I don’t work there anymore, and I don’t use that antivirus. So I uninstalled it and reinstalled VirtualBox. Still no luck. Still an antivirus conflict. Turns out the latest version of VirtualBox has a LOT of issues conflicting with every possible antivirus known to mankind. The commonly favored solution was to downgrade from 4.3.14 to 4.3.12, which could be done by just downloading the older build and running the installer without having to uninstall the new version of VB. That got it working just fine.

2) Create a new Virtual Machine

Once VirtualBox is installed, the next step was to create a new virtual machine to run Ubuntu on. Thanks to Quora, I found a great step-by-step on how to do this on the Navalay site. Steps 3 & 4 walk you through creating a virtual machine and adjusting the settings. All of that went through without any problems.

3) Mount Ubuntu on the Virtual Machine

The next step is to mount an Ubuntu desktop image to the VirtualBox machine and install it. You can download the ISO from here. Then follow the instructions under step #5 on Navalay.

One problem I ran into that could have totally been avoided… When I went to the downloads site, it detected my 64bit computer, and without thinking, that’s what I downloaded. When I went to go mount that to my virtual machine, I got all sorts of errors… because the virtual machine is 32bit, not 64bit (doh).

Once I realized what happened, I went back to the downloads site and got the 32bit version. That should have been all good, but for whatever reason, that first download attempt of the 32bit version must have been a corrupted ISO, because I got new errors. After Googling, the consensus was to try just redownloading and lo and behold, it finally mounted to my system.

4) Install Ubuntu Desktop

The second part of step #5 of the Navalay tutorial is the actual installation of Ubuntu. This should really be a breeze. Just click through the questions that the Ubuntu installer asks you and then restart. At this point, my computer just decided to hate me, and my Windows host graciously notified me that the VirtualBox program wasn’t responding. I lost the install of Ubuntu and had to go through the process again once I booted my virtual machine back up, and it worked just fine the second time.

5) Install Guest Additions

This is optional, but highly recommended. The “Guest Additions” CD image comes with the Ubuntu install and is super useful. It adds tools like auto-resizing your virtual machine window, being able to copy-paste between your host and guest, and some other things I haven’t really used yet. Just go to Devices > Insert Guest Additions CD and then hit Run on the window that pops up. Restart when you’re done and then you’re all set!

6) Increase Swap Memory

So this is one of the parts of the installation that left me feeling completely clueless. I ran into the concept of “Swap” pretty early because my host computer is old and doesn’t have a ton of RAM to begin with, so assigning more than 1GB of RAM to the Ubuntu box would be a pain. But… I’ve heard you really need at least 2GB of RAM to run Ruby on Rails properly. While I’ve learned that swap space isn’t a substitute for RAM, it at least allows the RAM to be used in the most efficient manner. I decided to go ahead and add a GB of swap space to my computer, in addition to the 750MB the Virtual Machine arbitrarily added as a partition during setup.

First, check how much memory you have on your machine:

$ free

will show you both RAM and Swap Totals, or you can use:

$ swapon -s

which will show you just the swap memory you have installed. Like I said, my Linux setup had already added 750MB as a swap partition. To add a 1GB swap file, I used the following commands in my Ubuntu terminal.

(A disclaimer, I found these commands here after a LOT of Googling what the best way to do this would be. Since it’s part of the official Oracle site, I trust it, but I honestly have little to no idea what it is that I actually did by executing these commands other than the fact that I now have more swap available.)

Login as root:

sudo su -

Enter the following commands:

dd if=/dev/zero of=/home/swapfile bs=1024 count=1048576
mkswap /home/swapfile
swapon /home/swapfile
swapon -a

Create a backup of the original “fstab” file and add the new swap file:

cp /etc/fstab /etc/fstab.backup_`date +%N`
echo '/home/swapfile swap swap defaults 0 0' >> /etc/fstab

Exit from root and verify the new swap space:

exit
swapon -s

That returned the following:

Filename        Type         Size      Used    Priority
/dev/sda5 partition 776188 192888 -1
/home/swapfile file 1048572 0 -2

So now I have the 758MB Partition plus a 1GB swap file to help take the load off of my tiny 1GB of RAM. We’ll see how that turns out once I start actually running things on here, but so far so good!

Summary

This whole process took the better part of 12 hours, thanks to the need for 4 restarts, several uninstall/reinstalls, wrong versions and corrupted downloads, and an unlucky computer day. If everything works perfectly the first time (hopefully reading some of my pitfalls will help), this could easily be done in a third of the time. Hope it helps!