Ruby on Rails Development on Ubuntu 9.04 (Jaunty) using Ruby 1.8.6
This guide details setting up a Ruby on Rails development environment under windows using VirtualBox 2.2.x, Ubuntu 9.04 and Ruby 1.8.6.
Ruby 1.8.6?!! Ruby 1.9.1 is Out Already!!
Ruby is currently on version 1.9.1, which sports a new JIT VM, providing much improved performance when compared to Ruby 1.8. The good news is that Rails, as of version 2.3.2, fully supports Ruby 1.9.1. The bad news is that several Ruby libraries have not been updated for Ruby 1.9.1. Please refer to IsItRuby19 to see a list of currently supported Ruby 1.9.1 libraries.
Being older (and hopefully wiser) makes me cautious of any new language and library releases. My preference would be to hold back on 1.9.1 for maybe another six months before I start migrating my code.
Developing on Windows?
Several posts have been made on setting up a Windows Ruby on Rails development environment, a good guide being posted by AkitaOnRails.
I am not a big fan of developing Rails applications on Windows. I host all my Rails sites on Ubuntu/Gentoo Servers and I would prefer my development platform to also be Ubuntu to minimise deployment problems.
This brings me to my last problem: My development machine is primarily a Windows based machine with 15 years worth of documents, tools, tweaks and Win32 based source code. I cannot change the OS on this machine to Ubuntu (as much as I would love to).
There are several alternatives:
- Cygwin under Windows. I have previously written about Cygwin and it still remains one of my most favourite (proper) shells under windows. Sadly, Ruby under Cygwin is much slower than Ruby under Linux. Also, Cygwin no longer officially maintains a Ruby 1.8.6 (more on this later) package in its repositories, now having moved to Ruby 1.8.7.
- CoLinux under Windows. Again, this is a good option but requires a few extra steps, specifically a windows based X-Server. I tried this for a few months but had to give up due to performance issues.
- VMWare Workstation and Ubuntu. VMWare Workstation is a commercial virtualization solution that allows installing several operating systems under Windows. This a viable commercial solution.
- VirtualBox and Ubuntu. My final option is very similar to VMWare exception being that VirtualBox is free when compared to VMWare Workstation.
My current preference is Ubuntu 9.04 running on VirtualBox 2.2.0 for the following reasons:
- VirtualBox is free.
- Much smaller footprint when compared to VMWare Workstation 6.5.x (60MB download when compared to a ~500MB download).
- VirtualBox supports OpenGL acceleration, so Ubuntu's Compiz desktop OpenGL based effects work under VirtualBox. Granted this is not essential... but it is nice none the less :).
- Ubuntu 9.04 sports JRE 1.6.0_13 which includes several performance boosts (more on this later).
A few words when comparing VMWare Workstation 6.5 to VirtualBox 2.2.x
- VMWare Workstation is more mature than VirtualBox so expect a few glitches in the latter. I will highlight these with workarounds.
- VMWare Workstation supports dual core processing so Ubuntu under VMWare is slightly smoother under load. VirtualBox counters this by being slightly faster.
- VirtualBox lacks VMWare's convenient ability to drag and drop files and folders to and from the Virtual Machine. VirtualBox's shared folder will have to be used instead for transferring files from the host to guest.
VMWare Workstation 6.5.2 can be downloaded (registration required) for a 30 day trial so do try both.
Getting Started
Steps 1 and 2 will detail setting up a virtual Ubuntu 9.04 environment under Windows. Skip to stage four if installing Ubuntu directly.
1. Download and install VirtualBox 2.2
Download VirtualBox 2.2.x here Double click to install and follow standard options and install network support and optionally USB support.
2. Download Ubuntu 9.04
Visit the Ubuntu Desktop Edition download page and choose your closest mirror. My recommendation would be to use the 32bit standard install CD ISO which can be downloaded on pressing the Begin Download button.
3. Install Ubuntu on VirtualBox
- Start VirtualBox and click the New toolbar button. Click Next on the Create New Virtual Machine Wizard. Choose a VM name and choose Operating System: Linux and version: Ubuntu. Press Next.
- On the Memory page, increase the memory to 1024MB (ensuring that your development machine has sufficient memory). This can be decreased but I wouldn't go lower than 512 MB. Press Next.
- On the Virtual Hard Disk page leave the defaults at Boot Hard Disk (primary Master) checked and select Create new hard disk option. Press Next. Press Next again.
- On the Hard Disk Storage Type select Dynamically expanding storage. The second option can also be chosen. Press Next.
- Select the location to save your VM and set a size of 12GB to give quite abit of breathing space. Press Next then press Finish on the Summary page.
- Select your newly created VM and press the Settings toolbar button.
- On the General Page, Disable 3D acceleration during installation. This can be re-enabled after stage 6.
- Press the Network page and select Attached to Bridged Network under Adapter 1. Ensure that Enable Network Adapter is checked under Adapter 1 and unchecked under Adapter 2,3 and 4.
- Press the CD/DVD-ROM page, check Mount CD/DVD Drive. Select the ISO Image File option and browse to your downloaded Ubuntu 9.04 Desktop Edition downloaded ISO file. Press OK.
- Press the Start button on the VirtualBox toolbar to boot the VM and install Ubuntu 9.04
4. Install Ubuntu 9.04
- Choose English (or your language) from the languages list and select the second option, Install Ubuntu. Press Enter.
- The installer should initialise in about a minute. Choose your Language from the Welcome screen. Press Forward.
- Select your Timezone. Press Forward.
- Select suggested option unless your keyboard is not United Kingdom. Test then press Forward.
- On the Prepare Disk Space page choose Use Entire Disk then press Forward.
- Fill in the Who Are You? details. Press Forward.
- On the Ready to Install screen press Install to start. This should complete in a few minutes (yes! A few minutes!!).
- On the Installation Complete dialog, press Restart Now.
- Press enter when prompted with Please remove the disk, close the tray (if any). This will reboot the machine. Press the F12 key on the Sun VirtualBox boot splash screen and select option 1) Primary Master.
5. Post Installation VirtualBox - Guest Additions.
You should be booted into Ubuntu 9.04. We should install GuestAdditions to enable guest resizing and improve mouse capture/release support.
- Your desktop should display a CD ROM icon labelled Ubuntu 9.04 i386. If so, right click on the icon and select Unmount Volume. The icon should disappear.
- On the VirtualBox guest window, press the Devices menu and choose Unmount CD/DVD-Rom. You wil need to press the right Control key to release the mouse from the VM.
- Select the Devices menu again and choose Install Guest Additions. A CD ROM icon labeled VBOXADDITIONS_2.xxxx should appear.
- Select the Ubuntu Application Menu then Accessories and finally Terminal.
- Inside the terminal type: sudo aptitude install dkms. Press Enter
- Inside the Terminal type: sudo sh /cdrom/VBoxLinuxAdditions-x86.run i. Press enter to install
- Once completed, you will be prompted to ".. restart your guest system in order to complete the installation". Type sudo reboot to restart the VM.
6. Post Installation Virtual Box - Mouse Tweaks
Once rebooted, Ubuntu should boot up with better video support. Unfortunately, VirtualBox 2.2.0 Guest Additions does not correctly install Mouse Integration for Ubuntu 9.04. To fix this select Applications -> Accessories -> Terminal, and type sudo nano /etc/X11/xorg.conf. press the Page Down key to scroll down the file. At the bottom, copy and paste (paste into the terminal using Shift + Control + V) the following:
Section "InputDevice"
Identifier "vboxmouse"
Driver "vboxmouse"
Option "CorePointer"
Option "Device" "/dev/input/mice"
EndSection
Press Control X to save then type sudo reboot to restart the VM one final time. This should now enable Mouse Integration. it safe to enable 3D Acceleration after this.
7. Post Installation - VirtualBox Host Key
By default VirtualBox sets the host key to the the right Control key. This is a slight inconvenience for me as I often use the right Control key plus the left and right arrows to navigate through code by word boundaries.
VirtualBox allows changing the Host key via the main VirtualBox window by clicking on the File menu -> Properties. Click on the Input page. Unfortunately there is a bug in VirtualBox 2.2.0 that prevents changing the Host Key using this form. Instead, the configuration file has to be manually edited.
The VirtualBox configuration file can be found in C:\Documents and Settings\YOUWINDOWSLOGON\.VirtualBox\VirtualBox.xml. Edit this file by adding the following:
Under VirtualBox > Global -> ExtraData XML nodes. This value would set the Host key to be the right Alt key.
<p><extradataitem name="GUI/Input/HostKey" value="165"></extradataitem></p>
8. Install Ruby 1.8.6 on Ubuntu 9.04 Jaunty Jackalope
Ubuntu 9.04 repositories contain both Ruby 1.9 and Ruby 1.8. Unfortunately, the jaunty repositories contain Ruby 1.8.7 when we actually want Ruby 1.8.6.
To fix this we need to add the Hardy repository to our sources and pin Ruby libraries to the Hardy repository
Open up the terminal (Applications -> Accessories -> Terminal) and type: sudo nano /etc/apt/sources.list. Scroll down (Page Down key) to the bottom of this file and paste (press Shit + Control + V) the following:
#Hardy Repos for Ruby 1.8.6 deb http://gb.archive.ubuntu.com/ubuntu/ hardy restricted main multiverse universe deb-src http://gb.archive.ubuntu.com/ubuntu/ hardy restricted main multiverse universe
Press Control + X to save. Type sudo nano /etc/apt/preferences and paste (Shift + Control + V) the following:
Package: ruby Pin: release a=hardy Pin-Priority: 900 Package: ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: rdoc1.8 Pin: release a=hardy Pin-Priority: 900 Package: ri1.8 Pin: release a=hardy Pin-Priority: 900 Package: libgtk2-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libdbd-sqlite3-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libopenssl-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libsqlite3-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: ruby1.8-dev Pin: release a=hardy Pin-Priority: 900 Package: libdbi-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libatk1-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libpango1-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libatk1-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libgdk-pixbuf2-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libglib2-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libcairo-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: irb1.8 Pin: release a=hardy Pin-Priority: 900 Package: libreadline-ruby1.8 Pin: release a=hardy Pin-Priority: 900 Package: libncurses-ruby1.8 Pin: release a=hardy Pin-Priority: 900
This effectively pins all Ruby related packages to hardy. Type sudo apt-get update followed by sudo aptitude install ruby rdoc irb libyaml-ruby libzlib-ruby ri libopenssl-ruby ruby1.8-dev to install Ruby 1.8.6. Confirm by typing ruby -v at the prompt:
The above process can also be used to pin Ruby to 1.8.6 on Ubuntu Server.
na@na-desktop:~$ ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]
9. Install Ruby Gems and Rails
Although Ubuntu does package GEM in its repositories it is my preference that GEM be installed from source. There is some controversy over whether Ubuntu should maintain Gems or RubyGems should. Personally, I would prefer it that Gems be maintained by RubyGems and not Ubuntu
To install RubyGem MySQL and Rails:
cd ~ mkdir gems && cd gems wget http://rubyforge.org/frs/download.php/55066/rubygems-1.3.2.tgz tar xf rubygems-1.3.2.tgz cd rubygems-1.3.2/ sudo ruby setup.rb sudo ln -s /usr/bin/gem1.8 /usr/bin/gem sudo gem update --system sudo gem install rails sudo gem install mongrel sudo apt-get install mysql-server libmysqlclient15-dev sudo gem install mysql
10. Installing a Ruby on Rails IDE
By now we have all the ingredients to start Rails development. The final piece of the puzzle is the editor. There are several options here but I will concentrate on two: Netbeans and RubyMine.
Some developers would prefer using a text editor such as the bundled gEdit under Ubuntu. gEdit is very capable and is able to syntax highlight Ruby code. My preference, however, is towards an intelligent editor that is capable of parsing all my Ruby files and is able to highlight errors and offer quick navigation between classes, controllers, views, tests and so on.
Of the later, there are two very excellent choices: Netbeans and RubyMine. Personally I am split between the two but here are some issues to be aware of:
- If you wish to use Git then Netbeans does not offer built-in Git integration. There is an excellent project called NBGit that attempts to address this but installation of NBGit under the latest development Netbeans builds is not straight forward. NBGit authors are currently addressing this.
- RubyMine has built in support for Git.
- Netbeans is a free IDE
- RubyMine, currently in beta, is free but will eventually be sold for $99. Having said that, a 50% discount coupon can be obtained here to purchase RubyMine for $50 when it is released.
My recommendation would be to try both as the final choice is a mater of personal preference as the set of features offered by both IDEs is very similar.
Both these require the JRE
11. Installing Sun Java Runtime Engine (JRE).
The Java JRE is available in two flavours: Sun's Java 6 JRE and the OpenJDK 6 JRE. In this instance we will be installing Sun's Java 6 JRE as the OpenJDK JRE has a few issues with both Netbeans and RubyMine.
sudo aptitude install sun-java6-bin sun-java6-fonts sun-java6-jre sudo aptitude install ttf-liberation ttf-mscorefonts-installer
I've added an extra command to install some additional fonts.
12. Installing Netbeans
Nightly Netbeans builds can be downloaded here. My recommendation would be to download the platform independent zip file, which is selected by choosing OS Independent ZIP next to the Platform dropdown box at the top right of the screen. Press the Download button under the ruby column:
cd ~ wget http://bits.netbeans.org/download/trunk/nightly/latest/zip/netbeans-trunk-nightly-200904260201-ml-ruby.zip unzip netbeans-trunk-nightly-200904260201-ml-ruby.zip netbeans/bin/netbeans #to start netbeans
Add Netbeans to the start menu by clicking the System menu -> Preferences -> Main Menu. Click on the Programming menu under Applications and press the New Item button. Name is Netbeans. Press the Browse button next to the Command edit box and select netbeans\bin\netbeans (not netbeans.exe). press OK.
Visit the Netbeans Ruby wiki for tips and the latest news.
13. Installing RubyMine
At time of writing the RubyMine RC can be downloaded here. You will also require the 30 day evaluation key from here.
cd ~ wget http://download.jetbrains.com/idea/rubymine873.tar.gz tar xf rubymine873.tar.gz na@na-desktop:~$ rubymine873/bin/rubymine.sh ERROR: cannot start RubyMine. No JDK found to run RubyMine. Please validate either RUBYMINE_JDK or JDK_HOME points to valid JDK installation exec: 60: /bin/java: not found
The above error can be overcome by editing rubymine.sh: nano rubymine873/bin/rubymine.sh and add the following RUBYMINE_JDK=/usr after #!/bin/sh.
Enter the Username and Licensekey from this page.
For more information on RubyMine, visit the Docs&Demos page. RubyMine user forums can be found here.
Nazar started programming on a Zx Spectrum in 1983, when the majority of games were supplied by magazines as source code and had to be keyed in by hand. Nazar started developing professionally in 1995, starting with Oracle Forms 3 and progressing to Delphi in 1998. He founded Panther Software Publishing in 2001 and has since developed and supplied numerous bespoke solutions to various sectors of industry, ranging from: Insurance, Banking, Facilities Management, Health Care, Engineering, Document Control and Procurement.
Panther Software has been specialising in developing bespoke database driven web applications using Ruby on Rails and AJAX since 2006. Contact us for your web application requirements.
Comments closed for this article
What others have said:
|
|
||
|---|---|---|
|
By: Anko
|
Care to elaborate on the reason for 6. Post Installation Virtual Box – Mouse Tweaks? I have a similar setup at work (virtualbox 2.2/ubuntu 9.04) but i have not needed this step. |
|
|
Posted 10 months ago
|
||
|
|
||
|
|
||
|---|---|---|
|
By: Derek
|
Thanks for the top on the mouse integration with 9.04. BTW, what’s wrong with 1.8.7? Seems to work fine with a large app we have. Derek. |
|
|
Posted 10 months ago
|
||
|
|
||
|
|
||
|---|---|---|
|
By: nazar
Joined: September 21, 2007
Posts: 18
|
@Anko It seems that under certain configurations Jaunty fails to detect the mouse correctly and hence VB Mouse Integration does not activate. This has been reported several times on VirtualBox’s forums. The mouse tweaks fix this issue @Derek I think later versions (i.e. Rails 2.1 and onwards) work fine with 1.8.7 although there have been some postings that suggest that earlier versions are not fully compatible. 1.8.6 is still seen the most compatible version to use for Rails hosting. |
|
|
Posted 10 months ago
|
||
|
|
||
|
|
||
|---|---|---|
|
By: Filip
|
You got it wrong in point "5. 6. Inside the Terminal type: sudo sh /cdrom/VBoxLinuxAdditions-x86.run if running Inter or sh /cdrom/VBoxLinuxAdditions-amd64.run if running an AMD processor." The "amd64" tag doesn’t mean that it is for the AMD processors. It means that it is the 64-bit version. Earlier you recommended "32bit standard install" so you’re wrong when suggesting "amd64" for AMD processors. There is no official name for 64-bit systems and AMD64 is one of the commonly used, for Intel 64-bit CPUs as well. |
|
|
Posted 10 months ago
|
||
|
|
||
|
|
||
|---|---|---|
|
By: nazar
Joined: September 21, 2007
Posts: 18
|
@Filip: Thanks for the feedback. I’ve updated the article accordingly. |
|
|
Posted 10 months ago
|
||
|
|
||









