Getting Started with Heroku on Windows

Heroku looks to be a very promising way of writing Rails applications with easy deployment, source control, and hosting all built-in.

Unfortunately, the windows story of Rails development, ruby gems, Git, SQLite, are all incredibly horrible, and make it tough to get started.  Wish I were on a Mac, but yeah… not on my laptop… yet.

Step 1:  Install Cygwin

I can’t stress enough how awesome this tool is.  it gives you a unix-style shell that supports a number of things, namely Git.  You can’t run Git on windows without msys-git or similar and it is required for Heroku.  (Git is the deployment mechanism for packaging up your changes and sending them to Heroku).

When you install cygwin, make sure to expand the packages and install *at least* the following:

  • gcc
  • gcc-g++
  • git
  • git-completion
  • git-gui
  • gitk
  • grep
  • gzip
  • libsqlite3-devel
  • libsqlite3_0
  • make
  • man
  • openssh
  • ruby  <—some say this is buggy, but it seems to work for me
  • sqlite3
  • tar
  • wget

Wait for it to download and install those packages.  There might be others, but those are the major ones installed on my machine.  If you already have cygwin installed, you can run the setup.exe file again and select the packages you’re missing.

Step 2:  Install Rubygems

Note that this is required even if you already have the one-click ruby installer on windows.  Steven Harman wrote about how to do this in cygwin:

  1. Download the RubyGems tarball from Ruby Forge
  2. Unpack the tarball
  3. In a bash terminal, navigate to the unpacked directory
  4. Run the following command:
    ruby setup.rb install
  5. Update RubyGems by running the following:
    gem update --system

Note: You may need to run the updated command twice if you have any previously installed gems.

Note, if you try to run some ruby files and you get a “could not load rubygems” error, you may need to unset the RUBYOPT environment variable.  The windows version might be conflicting with the cygwin version.

Step 3:  Install sqlite3-ruby gem

The sqlite3-ruby gem is actually a CGem (not ruby) so it needs a windows binary. Unfortunately, there isn’t a windows version yet, so you need to back up to the latest one that does, which is 1.2.3 as of this post.

gem install sqlite3-ruby –v 1.2.3

If this fails with an error saying “looking for sqlite.h…no” then you probably haven’t installed the libsqlite3_devel package in cygwin. This tripped me up.

Step 4: Install json gem

Again, the latest version of this gem doesn’t work yet with Windows, so you have to request version 1.1.1.

gem install json –v 1.1.1

 

Step 5: Install Heroku gem

gem install heroku

 

Step 6: Create an SSH key file

In order to communicate securely with heroku, you need to create an SSH key file.

$ cd ~/
$ mkdir .ssh
$ cd .ssh
$ ssh-keygen –C “my key” –t rsa

 

This should create a public & private key file.  Heroku will look for this.

Now we can follow the standard heroku instructions, which are pretty simple.  Here’s how you’d create a sample rails app, initialize git, add files, and create the app on heroku.  Finally we’ll push the code & you can see it running online.

$ rails foo
$ cd foo
$ git init
$ git add .
$ git commit –m “adding files”
$ heroku create (type in heroku credentials when prompted)
$ git push heroku master

 

You’ll be given a URL when you create the app on heroku, so after you push you can visit http://your-app-name.heroku.com to see it live!

Hope this helps someone else get started faster than me!

#1 Robz avatar
Robz
6.18.2009
2:27 PM

Sweet!

When are you going to hackintosh the laptop?


#2 benscheirman avatar
benscheirman
6.18.2009
2:35 PM

I've read about my Dell D820 & hackintoshes, and some key things like the wifi card aren't really supported. I just need to buy a real MBP!


#3 Chris Bilson avatar
Chris Bilson
6.18.2009
5:01 PM

This is really helpful, Ben. Thanks!

Have you considered just using linux on your Dell? I bet everything on it is supported, ubuntu is a breeze to install, and the platform just doesn't fight you when you want to do ruby development. Just a thought.


#4 benscheirman avatar
benscheirman
6.18.2009
5:03 PM

I've tried getting into linux before. It's just not me I guess. :). Aesthetics are a part of that.


#5 Christian avatar
Christian
8.13.2009
1:34 PM

Ubuntu. Is. Awesome.


#6 Adrian Short avatar
Adrian Short
8.28.2009
9:14 AM

Thanks, that was really useful.


#7 Rico Wang avatar
Rico Wang
9.11.2009
9:04 AM

I Got message.I deleted this article.


#8 Andrei avatar
Andrei
9.22.2009
5:04 PM

Hi, Ben! I have got such error message trying to push my app to heroku:

Permission denied (publickey).

fatal: The remote end hung up unexpectedly

Any ideas about the reason?

I have made SSH-key file several times... probably in a wrong way.


#9 Andrei avatar
Andrei
9.22.2009
6:19 PM

Fixed. It was either git user settings or HOME directory setting. May be both.


#10 tkm avatar
tkm
10.26.2009
5:58 PM

I had to move the key files id_rsa and id_rsa.pub to

C:\msysgit\msysgit\.ssh folder to get the permission denied (publickey) error to go away.

When those files were generated using ssh-keygen, I put those in my home directory .ssh folder.


#11 Greg Dean avatar
Greg Dean
11.12.2009
9:22 PM

You're the man. This even helped me with an Ubuntu install. Many thanks!