Nov 2, 2007

Quick Ruby on Rails on Ubuntu 7.10 (and 8.04 and 9.04)

There are many howto's on this subject out there, but since I ended up blending a few of them to get exactly the environment I wanted setup (and took notes so I could repeat this), I thought I'd blog it for future reference, and hopefully this info is useful to others.

So, what exactly do I want: a development and deployment machine with the following specifications:
  • A recent Ubuntu Linux, in this case 7.10 (Gutsy Gibbon) [update: I also installed on 8.04, hardy heron beta, with good success]
    [update2: I have now installed on 9.04, with a few changes]
  • Web-App server comprised of apache2, mongrel, ruby on rails, mysql5
  • Development environment comprised of Aptana RadRails (based on eclipse), for both Java and Ruby on Rails development (I use Java for other projects, but also plan to do some JRuby work), and since eclipse rocks, I use it for everything I can, even rails. If you don't want java development, you can use the pure Aptana IDE, but then you also loose out on CVS support).
  • Some additional libraries for graphics and charting support in the rails apps.
The quickest setup procedure that worked for me, on four very different computers, a Dell Precision 380 desktop, an Acer Aspire 3100 laptop and most recently a Packard Bell quad core workstation and Acer Aspire 7530G, was:
  1. Install ubuntu. I simply did a standard install from the live cd (downloaded from www.ubuntu.com)
  2. Update all packages. I usually just click the update icon on the top right of the screen, but you can use synaptic ('mark all updates' and then 'apply'), or apt-get with the following commands:
    • sudo apt-get update
    • sudo apt-get upgrade
  3. Install packages required for this setup. I used synaptic, but you could just as easily use 'sudo apt-get install ...':
    • sun-java6-jdk / openjdk-6-jdk (includes a number of other required packages)
    • sun-java6-source / openjdk-6-source (optional)
    • joe (just my preferred old text editor, you choose what you like)
    • flashplugin-nonfree (since I will need that for some sites I view/develop)
    • ruby-full (bundles a bunch of ruby packages, including irb, rdoc and ri, but not rake and rubygems, see later for those - do not install them as ubuntu packages now)
    • apache2 (provides version 2.2)
    • mysql-server (provides version 5.0)
    • libsqlite3-dev (required for the gem install of sqlite3-ruby, if you need that)
    • build-essential (provides a c/c++ development environment required by some ruby gems which build on install)
    • libmysqlclient15-dev (required by the mysql ruby library)
    • eclipse (for 3.2 support in ubuntu 7.10 and 8.04) - to get eclipse 3.3 or 3.4 you need to download it from www.eclipse.org.
    • On recent versions of Ubuntu (like 9.04) you also need to install xulrunner as described at this link. This is to get around a library issue between SWT (in eclipse) and Firefox3.0.
  4. Install rubygems from source. This is a contested point, as ubuntu provides rubygems as a package also, but since it is a package management facility itself, it can conflict with the debian package management provided by ubuntu, so it is easiest to keep it completely separate:
    • wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz
    • tar xzvf rubygems-1.3.4.tgz
    • cd rubygems-1.3.4
    • sudo ruby setup.rb
    • sudo ln -s /usr/bin/gem1.8 /usr/bin/gem # This was not required for rubygems 0.9.4, but is required now on ubuntu with rubygems 1.0.1 and above
    • sudo gem update --system # With 0.9.4 I needed to repeat this as the first time gave an error, but with 1.0.1 and 1.3.4 it worked first time
  5. Use rubygems to install rails and some other useful gems using the command 'sudo gem install X' where X is any number of the following (I did all):
    • rails # this includes dependencies like rake
    • mongrel # for the deployment server
    • mongrel_cluster # if you want to try out clustering
    • capistrano # if you want to do the easy deployment as described in the 'agile' book
    • mysql # for mysql database access from ruby
    • termios # well, this was mentioned in several blogs and the agile book, so I just did it :-)
    • sqlite3-ruby (sqlite3 is now the default database in rails2, so you might need this)
  6. Add the Aptana Radrails plugins to the eclipse IDE:
    • Start eclipse from the applications menu
    • Go to menu 'Help->Software Updates->Find and Install'
    • Select 'Search for new features to install' and click 'Next'
    • Click 'New Remote Site'
    • Enter name as 'Apatana' and URL 'http://update.aptana.com/install/3.2' and click OK
    • Click 'New Remote Site' again
    • Enter name as 'Apatana Radrails' and URL 'http://update.aptana.com/install/rails/3.2' and click OK
    • Click 'finish' to start the search for updates
    • Once the search is complete, you should check both 'aptana' and 'aptana radrails' and click 'next' to install
    • Accept the license agreement and click 'next' and then 'finish' to start the actual download
    • When prompted click 'install all' to finish the install
    • Restart eclipse
  7. Modify Eclipse to use Java6 (based on http://help.ubuntu.com/community/EclipseIDE). For Ubuntu 8.04 and 9.04, this was not necessary, but I did it for Ubuntu 7.10 and earlier.
    • edit /etc/eclipse/java_home and move java6 up in the list so that eclipse uses java6 for running itself (which is faster)
    • To get projects inside eclipse to use java6, open eclipse and go to the menu 'Window->Preferences->Java->JREs' and select the Java6 JRE.
  8. Add some extra libraries to rails (optional, depends on your apps):
    • I wanted ImageMagick for photo uploads and resizing in my rails apps, so I installed the ubuntu package for ImageMagick using synaptic, and then installed the rubygem 'mini-magick'. I had tried 'RMagick', but the gem did not install, and online help indicates that you need to re-install ImageMagick from source to get RMagick to work, so I opted for the simpler mini-magick.
    • For charting support in my web apps, the popular approach of using 'gruff' wrapping ImageMagick seemed to generate a lot of help requests, so I went for the lighter approach of using client side flash as described in the following blog.
    • For nicer color control, I installed pdf-writer to get the color-tools gem (and in case I needed pdf-writer itself for future development).
  9. Once you have created a rails app, using the usual 'rails myapp', you should consider adding a number of cool rails plugins. There are a huge number out there. Currently I'm using attachment_fu, will_paginate, acts_as_state_machine, restful_authentication and ext_scaffold. See some of my more recent blogs for some more info on these.
  10. Miscellaneous. I also changed my ubuntu font sizes down to 9pt on 'system->preferences->appearance' to get a bit more screen real-estate on the laptop. Windows uses smaller fonts so it looks better (to me), especially when developing in an IDE like eclipse where it is nice to have many panels open together. And for some reason the Ubuntu install had visual effects disabled (Composite extension not available), so I needed to edit /etc/X11/xorg.conf and change the "0" to a "1" on the Composite line near the end of the file. And I changed the theme to 'glossy' but with 'human' icons and darker colors. Looks cool now!
Well, quiet a few steps, but most of the time the computer is downloading packages, updates, plugins and gems from the internet, so you can just lounge around with a good latte :-)



And of course the required screenshot, this one is of the Acer laptop with firefox showing this page and eclipse with a Ruby on Rails application in production (ubuntu 7.10).

Next steps - there are lots of blogs out there on setting up production deployments for rails, and here's one I just read: http://www.urbanpuddle.com/articles/2008/01/09/install-ruby-on-rails-on-ubutu-gutsy-gibbon-apache-version

Jun 1, 2007

VMWare & Dual-Boot Ubuntu Feisty and Windows XP

A long title I know, but I had to do some serious google searches to get this to work, and it was thanks to other long titles that I found the info I needed. So let me start with the references:
  1. VMWare's document: Configuring a Dual-Boot Computer for Use with a Virtual Machine - good background info covering many (but not all) issues.
  2. Running VMWare on a Physical Partition by Scott Bronson is a really good howto-style article with most of the details you need to do the job step-by-step.
  3. How to install Vmware server From Canonical commercial repository in Ubuntu Feisty - that got me onto the easy install route
  4. HOWTO Configure a dual boot windows linux to be able to open each os in vmware - gentoo based article, but had an interesting suggestion for windows IDE drivers.
So, as the first vmware document says, this is not necessarily a very easy thing to do, getting the same OS installation to boot on both the real physical machine and the virtual machine. Most issues relate to the different drivers and configurations required, or to the multitude of boot problems. However, the documents above, and the second one in particular, covered most of what I needed. So if you have a similar setup to me, you should be able to get this working OK by following that second article, with a few small changes suggested below.

So why did I bother to write this article? Well, not one of the above articles was enough to cover my setup, and I did not find any real help (hints, but not explicit help) for some of the problems I had:
  • My SATA drives are seen by Ubuntu as SCSI drives, but by Windows as IDE drives, preventing windows from even booting in VMWare without installing the vmscsi drivers *before* booting windows!
  • Any change I made to the Ubuntu network configuration after setting up vmware completely broke the vmware installation (and made gnome runs super-slow). This seems to be a edgy-feisty problem, and a google search found the solution (add the hostname to 127.0.0.1 in /etc/hosts - simple!)
So, let me outline the basic approach I took to get windows running inside ubuntu. The reverse is possible, and covered in the above articles, but I focused on this approach only.

My setup:
  • Dell Precision 370 with SATA drives, 2GB RAM, Dell 20" flatscreen (1600x1200)
  • Windows XP installed on C: (/dev/sda1)
  • Ubuntu Feisty (7.04) installed on /dev/sda3
Installation procedure:
  • Install the OS's (I think it is best to install windows first, making the C: partition 50% of the space and leaving the rest for Ubuntu, but other routes usually work too).
  • Make sure dual boot works, disable the timeout in grub so you are always forced to choose the OS (for now) - see article 2 above.
  • Under linux:
    • Prepare the disk as in article 2 (see article 1 for more info)
    • Install vmware-server from the canonical commercial - see article 4 above, or just use: deb http://archive.canonical.com/ubuntu feisty-commercial main
    • Make a floppy with the windows SCSI drivers from VMWare (either write a floppy with dd, or mount the image and copy the files to the windows partition)
  • Under windows
    • Prepare windows as in article 2 above (again article 1 has more info)
      • Make sure you make the two hardware profiles, and reboot to the new virtual profile for any driver changes.
      • Also install the vmscsi drivers by running the 'add hardware' wizard of the control panel, and clicking 'no I have not connected the hardware yet' to get windows to allow you to install the scsi drivers even through it cannot see any scsi hardware.
      • Consider changing the IDE drive as in article 4, although I'm not sure that was really required
  • Back in Ubuntu create the virtual machine according to article 2 (and reference article 3 for Ubuntu specifics if you need).
    • I recommend choosing the entire disk, not the partitions, as this seems to help a lot with windows/linux/vmware different views of the partition table.
  • Start the virtual machine as in article 2 and install VMWare tools (which will re-install the scsi drivers, but we needed to do that before this just to get it to boot in the first place).
  • Prepare the GRUB bootdisk for user-free reboots according to article 2. This is great because you can (mostly), not worry about rebooting to the wrong OS, or having the same OS running on both the hardware and the vmware at the same time (which would be disastrous). There are no solution to having to choose the windows hardware profile, but if you are like me and normally run windows inside linux, then having the virtual profile first, with a timeout, is great because even if you do boot the virtual profile on the real hardware by mistake and mess it up, it is much less serious than messing up the physical machine profile, and you can simply re-create the virtual profile by repeating some of the steps above.
Finally, more info on the two problems I had:
  • The need to install the vmscsi drivers in the windows virtual profile, but with windows booted onto the physical machine, is covered in the discussion above.
  • The issue with slow-gnome and broken vmware-server is really strange and I do not know the inner reason, but adding the line '127.0.0.1 localhost hostname' to /etc/hosts (with 'hostname' changed to your host), magically solves it. I wonder if the problem is related to the mysterious '127.0.1.1' line in the hosts file?
And, last of all, here is the obligatory screenshot showing the ubuntu desktop, with gimp and a gnome game running above the VMWare server console with Windows XP running eclipse showing a Ruby on Rail application with InstantRails windows as well. I know it's weird to be doing ruby and rails development in Windows, but I just happened to get started there, and I like the fact that eclipse on XP has nice compact fonts by default.

May 4, 2007

Amanzi Snippets

Recently I've begun giving a weekly series of ultra-short tech talks to the other developers in our office. The original problem we had was that, while we were all interested in learning about, or hearing about, technologies outside our working domain, it was generally not possible to spent office working hours on projects not directly of benefit to the company. The solution has been to give 15 minute talks during normal coffee-breaks. One really positive aspect of this is that it forced me to focus on a single specific 'hot' topic, and thereby blocking my usual tendency to lecture on for hours. While the resulting tech-talks are not comprehensive, they were easily digestible. Anyway you can always go to the books referenced below if you want something comprehensive.
These ‘snippets’ follow my progression as I learned Ruby, JRuby and Rails from the books I read, internet articles, and trial-and-error with real scripting projects I did. Each week I thought of something that was of particular interest to me as a Java and sometimes Perl programmer, and presented it in a 2-4 slide ‘snippet’. Where possible I used examples directly relevant to the work we do, which is mostly Java programming of data models and numerical analysis in mobile phone networks (not mobile phones). Sometimes I used examples from the books I read along the way:

For a more specific Ruby-2-Java comparison, see the extract in ComputerWorld of the book ‘Rails for Java Developers.’ This is a nice soft intro to Ruby for Java developers. However, while my snippets are not as complete, I think they are more interesting and relevant to me, of course. And I hope they will be of interest to others too.

Mar 28, 2007

Amanzi Down Under

My other brother and his wife have recently moved to the remote north west of Australia and started blogging from there too. Interesting place. I'd love to visit, but damn it's far away!