Fickle Bits

You're doing it wrong.

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:

    1
    
    <em>ruby setup.rb install</em>

  5. Update RubyGems by running the following:

    1
    
    <em>gem update --system</em>

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.

1
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.

1
gem install json –v 1.1.1

 

Step 5: Install Heroku gem

1
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.

1
2
3
4
$ 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.

1
2
3
4
5
6
7
$ 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!

Comments