Walkthrough: Ruby on Rails on Windows Azure

I setup Ruby on Rails on a new shiny Windows Azure VM instance today and I thought I’d share this walkthrough on how to get yourself up and running.

First off, you’ll need a virtual machine running one of the Linux distributions. To do that, go to your Windows Azure management console and click “+ New” -> “Virtual Machine” -> “From Gallery” -> “Ubuntu Server 12.04”.

Move to page #2 and name the machine (I called mine “frontend”) and choose a username and password. On page #3, choose a DNS name for the url that you’ll use for this app (you’ll need it down below, so make a note of it). On page #4, just accept the defaults.

After a minute or so of provisioning work, your VM should come up and go green.

Using your favorite SSH program, attach to a shell on the machine by using the login credentials you created previously and the DNS name you assigned above.

ssh <username>@<dns-address>.cloudapp.net

Entering your password should drop you to the Linux command line in your VM.

Ok, we’re ready to get started! The first thing we need to install is RVM (Ruby Version Manager). You can do that like this:

curl -L get.rvm.io | bash -s stable

This should download and setup rvm. You only then need to source rvm’s script to get all of the paths loaded into the environment.  Look in the output of the last command for the appropriate command for you (mine given as reference below).

source /home/testapp/.rvm/scripts/rvm

Next, we need to find out what dependencies we have for installing ruby. rvm has a command for that.

rvm requirements

Copy the requirements and prepend them with a sudo to install them (below are my dependencies as of this writing for reference):

sudo /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

Now that we have the ruby version manager and dependencies, installing Ruby is easy. I’ll use 1.9.3 here, which is the current stable version:

rvm install 1.9.3

This will take some time to complete. Afterwards, we’ll want to make this the default version as well:

rvm use 1.9.3 --default

Next, we’ll install RubyGems, the package management app for Ruby:

sudo apt-get install rubygems

and then install the Ruby on Rails gem using RubyGems:

sudo gem install rails

Finally, we need a javascript runtime for Rails. I’ll install that here by installing node.js to keep it simple.

sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm

All of the installation work should now be completed. Let’s create a test application to try it all out:

cd ~
rails new testapp
cd testapp
rails server

This fires up the Rails WEBrick development server with the default port binding (3000), which you can open up to the world from the Azure virtual machine dashboard for this machine. Click “endpoints” at the top, select “Add Endpoint” at the bottom, and add a TCP endpoint with the name “web” and public/private ports of 3000, and, voila, that should be it. You should have a running Ruby on Rails application on Azure — typing http://<name of your app>.cloudapp.net:3000/ in your browser should bring up the default Rails home page.

Using the development WEBrick server is obviously not production ready, but given that this is real honest to goodness Ubuntu machine, there are existing walkthroughs for getting passenger and NGINX setup that can help you through that.

Leave a comment