Virtualised Ruby on Rails development environment for dummies

Ruby, Software, Virtualisation 3 Comments »

Ruby development was always meant to be done on a *nix platform. For a while now I’ve been putting up with the Windows XP / Cygwin combination on my laptop to give me a pseudo-*nix environment. While this is a workable compromise, it is far from ideal. A lot of the Ruby tools don’t work well on Cygwin: crashes and mysterious hangings are common, execution times are slow and frustration is high.

The common solution to this problem is a walk to the closest Apple shop to get a shiny new Mac, but I’m not cool enough for a Mac so I decided to try something more befitting my coolness level: A Linux virtual machine running on my Dell laptop.

These are the steps you need to get a Ubuntu Virtual Machine running Rails over MySQL on your Windows machine.

Step 1: Setup a Virtual Machine (VM)

First we need to get a virtual machine configured and running with a *nix Operating System. I’ve chosen Ubuntu Server because all I need is shell access. You can use Ubuntu Desktop if you plan to use the VM as your development desktop.

  1. Download the latest version of VMware Server or VMware Player. VMware Player is a lighter download but can only operate VMs, VMware server can operate and create VMs. Either will work for our purposes, I used VMware Server.
  2. Download and unzip the latest Ubuntu Server VMware image. I used version 7.10 Gutsy Gibbon.
  3. Start VMware Server, point it at the downloaded image and start it.
  4. The virtual machine will start up and should come up with a login prompt. Hit Enter a couple of times on the console if it doesn’t.

Step 2: Get access

In this step we create a user on the VM and configure it for external shell access through SSH.

  1. Login using the username “notroot” and the password “thoughtpolice”.
  2. Install OpenSSH.
  3. > sudo apt-get install ssh

  4. Create yourself a user.
  5. > sudo adduser –shell /bin/bash <user_name>

  6. Add the user to the admin group (so they can do sudo, you can play around with sudoedit instead if you like).
  7. > sudo usermod -g admin <user_name>

  8. Get the IP address of the virtual machine.
  9. > sudo ifconfig eth0

  10. Fire up your favourite terminal program (I use PuTTY) and SSH to the VM using the user you created above.

Step 3: Install Ruby, Ruby on Rails and MySQL

Now we install some core development packages.

  1. Update the package index.
  2. > sudo apt-get update

  3. Install Ruby and related tools.
  4. > sudo apt-get install ruby rubygems irb ri rdoc ruby1.8-dev build-essential

  5. Install Ruby on Rails.
  6. > sudo apt-get install rails

  7. Install MySQL.
  8. > sudo apt-get install mysql-server

Step 4: Create a Rails project and fire it up

We have everything we need, let’s create a Rails project and access it from Windows.

  1. Create a Rails project in your home directory.
  2. > cd ~/projects
    > rails killerapp
    > cd killerapp

  3. Create a database.
  4. > mysqladmin -u root -p create killerapp_development

  5. Configure the database in your Rail application config/database.yml.
  6. Start the WEBrick server. You have to bind it to the external IP address (not localhost) to make it available though windows.
  7. > ./scripts/server -b <vm_ip_address> &

  8. On your favourite Windows browser, navigate to: http://<vm_ip_address>:3000/.The default Rails landing page should come up! You can add this IP address to the Windows hosts file to avoid having to remember it.

Step 5: Set up Samba (optional)

It’s useful to be able to share files between the VM and Windows, especially if you plan to use a Windows based IDE like Eclipse to craft your code. VMware has a “Shared Folders” feature but I gave up trying to get it to work after several hours of bashing my head against Google. I reverted back to Samba, which is trivial to configure.

  1. Install Samba.
  2. > sudo apt-get install samba

  3. Add the user to the smbpasswd file.
  4. > sudo smbpasswd -a <user_name>

  5. Open the Samba configuration file for editing.
  6. > sudo vi /etc/samba/smb.conf

  7. Remove the ‘;’ from the line that says “security = user,”.
  8. Add the following to the end of the file.
  9. [<user_name>]
    path = /home/<user_name>
    valid users = <user_name>
    read only = No
    create mask = 0777
    directory mask = 0777

  10. Save and close the file.
  11. Restart Samba.
  12. > sudo /etc/init.d/samba restart

  13. On Windows Explorer, Map Network Drive \\<vm_ip_address>\<user_name>, login using “<user_name>”.

That’s it! I haven’t used this environment in anger yet so there are bound to be some holes, let me know if you fall into any.

Code complexity vs size

Java, Ruby, Software 4 Comments »

Steve Yegge (one of my favourite bloggers) recently posted about the maintenance problems exhibited by a large Java code base. I agree that software bloat is one of the biggest problems in our industry right now.

His proposed solution is to re-implement the 500,000 lines of Java code into 150,000 lines of a more concise language such as Ruby or JavaScript (ES4). This approach seems misguided to me because software complexity is not directly proportional to number of lines of code. The fact that 5 lines of Java can sometimes be compressed into 1 line of Ruby does not make the logic less complex or easier to maintain if they are essentially doing the same thing. In fact, I would argue that often 1 line of clever Ruby is actually less maintainable that 5 lines of Java because it requires a deeper understanding of what’s going on underneath the covers.

A good case study is Perl where developers seem to be a mind set of “how clever can I be” and write one liners that become indecipherable even by the author within days. You might be able to get away with this if you’re a gun developer working on your own but not if you’re working in an average team of average developers. I think Ruby has actually struck a nice balance between readability and conciseness and this is one of the reasons why its popularity has surged. Still, the thought of a 150,000 line Ruby code base scares me and would keep me up at night if it was left in the hands of average developers.

A code base with 1000 Java classes is just a complex as a code base with 1000 equivalent Ruby classes even if the number of lines per class is less. Reducing complexity and therefore increasing maintainability is all about applying good software engineering principles and frequent doses of my favourite refactoring — Delete.

Vendor support for Ruby

Java, Ruby, Software No Comments »

A few weeks ago I did some work for a client that is about to re-platform a public facing website written in Forte 4GL to Java. Forte itself is not the problem, as far as I can tell the technology is sound. Forte is a legacy platform that is no longer supported by Sun. The client is finding it impossible to hire people that have the required skills and want to work on Forte applications. The business wants to make some significant upgrades to the application. Sensibly, the client does not want to invest any more money into a legacy platform so they have kicked off the effort to re-platform it to Java at a considerable cost.

So far, this is an all too common story. There are legacy platforms and applications everywhere. What really surprised me is that the current application is only 4-5 years old, which tells me that Forte went from mainstream to legacy in an amazingly short time.

All this is interesting background in the context of what’s happening with Ruby at the moment. The popularity of Ruby is increasing all the time and we’re finding that corporate clients are starting to choose Ruby over Java more and more. Is this a gamble? Does anyone know where Ruby will be in 5 years time? 10 years? Will the current mob of smart people gathered around Ruby have moved on to the Next Great New Language? I can understand why CIOs are cautious of Ruby, I would be too.

One important consideration is the part played by the open source and Ruby communities. Vendor support is something that corporates traditionally appreciate, it gives them a warm fuzzy reassuring feeling. But in this case Sun bought out Forte and essentially killed it to neutralise a rival to J2EE. Thanks vendor! Ruby is not owned by anyone so the risk of it being exterminated is minimised. If Ruby dies it will be due to natural causes.

Java is an interesting case study because it managed to strike a nice balance between vendor support and a strong community. In the initial stages Sun invested a lot of effort developing, promoting and selling Java despite it’s well documented shortcomings. Sometime in the late 90’s the community around Java really took over and was responsible for making Java mainstream. Java is now owned by the community, just like Ruby.

The case for Ruby in the enterprise could certainly benefit from some vendor support. Efforts to deploy Ruby applications on accepted enterprise platforms will also be key (e.g. JRuby, IronRuby).

© 2007 Tomas Varsavsky, All Rights Reserved. WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Login