So What's Heroku?
Heroku is effectively a cloud-based web application platform. By using it you don't have to worry about any physical hardware - Heroku'll take care of it. This is pretty groovy when you just want to put a site up and not worry about getting the actual boxes plugged in and running. On top of that, Heroku supports most of the trendier platforms and languages. In particular, they support Ruby on Rails, which we'll be using here. Pricing can be a little tricky, but for a quick application, one web worker thread with the smallest shared database is free. This is enough for our purposes. We'll be assuming that Ubuntu 11.10 is the operating system of choice.
Setup your Account
The first thing that needs to be done is setting up your account. The signup page is pretty straight forward. Heroku is nice enough to link everyone to their own quick start guide, which we will be paraphrasing here. You'll first want to grab the Heroku toolbelt, which is a client-side application that you can use to manage your applications. On Ubuntu, you just need to run...
wget -qO- https://toolbelt.heroku.com/install.sh | sh
...to install the toolbelt. Typing...
...will prompt you for your Heroku username and password. It will also ask if you want to generate and upload a SSH key for your account - you'll want to do that so you don't need to later. At this point you have a working Heroku user account and can authenticate against it.
Installing Ruby and Rails
For whatever reason, this can be kind of tricky on Ubuntu, particularly if Ruby or Rails is already on the system or was installed by aptitude. Luckily, we've made a script that takes a lot of the pain out. It is specifically for Ubuntu 11.10, but feel free to modify it to serve your purposes:
sudo apt-get update
sudo apt-get install build-essential git-core curl postgresql libpq-dev
bash -s stable < <(curl -s https:
'[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"'
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-
libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
gem install rails -v
Creating your Application
You'll want to make a new folder for this - let's place it in ~/projects. From the projects directory, do...
heroku create --stack cedar
This will have Heroku create your actual application. It will have an application name in the form of adjective-noun-####. If you open a browser window and visit adjective-noun-####.herokuapp.com, you should see a Heroku welcome page. It's easiest to pull down the repository via git to actually put rails on it. For this, you should do something like
git clone email@example.com:adjective-noun-####.git
The actual repository is empty at this point, but the clone operation will create the application folder in your projects directory. We're now going to do something loosely like the guide here. First, we need to create our Rails app locally. From the projects directory, we can create it with
rails new adjective-noun-####
This will populate your application folder with a Rails skeleton. We then need to swap out the sqlite3 gem for the PostgreSQL gem from the Gemfile in the root of the application folder. Just change...
and then run 'bundle install' to grab the correct PostgreSQL gems. We can then commit and push our changes to our Heroku server with
git commit -a
git push origin master
If all goes well, Heroku will compile and run the pushed Rails app. If you visit your application web site in a browser, you should see this:
If so, all is well, and you now have Ruby on Rails running on the Heroku environment. Happy hacking!