Virtualised Ruby on Rails development environment for dummies
Ruby, Software, Virtualisation Add commentsRuby 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.
- 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.
- Download and unzip the latest Ubuntu Server VMware image. I used version 7.10 Gutsy Gibbon.
- Start VMware Server, point it at the downloaded image and start it.
- 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.
- Login using the username “notroot” and the password “thoughtpolice”.
- Install OpenSSH.
- Create yourself a user.
- Add the user to the admin group (so they can do sudo, you can play around with sudoedit instead if you like).
- Get the IP address of the virtual machine.
- Fire up your favourite terminal program (I use PuTTY) and SSH to the VM using the user you created above.
> sudo apt-get install ssh
> sudo adduser –shell /bin/bash <user_name>
> sudo usermod -g admin <user_name>
> sudo ifconfig eth0
Step 3: Install Ruby, Ruby on Rails and MySQL
Now we install some core development packages.
- Update the package index.
- Install Ruby and related tools.
- Install Ruby on Rails.
- Install MySQL.
> sudo apt-get update
> sudo apt-get install ruby rubygems irb ri rdoc ruby1.8-dev build-essential
> sudo apt-get install rails
> 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.
- Create a Rails project in your home directory.
- Create a database.
- Configure the database in your Rail application config/database.yml.
- Start the WEBrick server. You have to bind it to the external IP address (not localhost) to make it available though windows.
- 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.
> cd ~/projects
> rails killerapp
> cd killerapp
> mysqladmin -u root -p create killerapp_development
> ./scripts/server -b <vm_ip_address> &
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.
- Install Samba.
- Add the user to the smbpasswd file.
- Open the Samba configuration file for editing.
- Remove the ‘;’ from the line that says “security = user,”.
- Add the following to the end of the file.
- Save and close the file.
- Restart Samba.
- On Windows Explorer, Map Network Drive \\<vm_ip_address>\<user_name>, login using “<user_name>”.
> sudo apt-get install samba
> sudo smbpasswd -a <user_name>
> sudo vi /etc/samba/smb.conf
[<user_name>]
path = /home/<user_name>
valid users = <user_name>
read only = No
create mask = 0777
directory mask = 0777
> sudo /etc/init.d/samba restart
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.
February 25th, 2008 at 12:04 pm
Buy a mac! You know you want to.
March 4th, 2008 at 10:46 pm
Cool Tomas, Though I figured out all this myself and am using it since long, it was good to find that you have documented it quite well here. Thx!
May 28th, 2008 at 11:07 pm
@Richard Durnall
Don’t make stupid comments, you know you want to!