Deploy Rails app from Github to Heroku

Recently I found deploying your Rails code which already on Github to Heroku is very useful. You can use this to show your work to your customers, friends …. Let’s start


== Generate a keypair

cd ~/.ssh
ssh-keygen -t rsa -C “”
(enter at first prompt)

Then go to your github account then add that key in Should use a text editor then ctrl-A to select all.

== Test if key works


If you see “successfully authenticated”, everything’s on rails.

== Create a new repo

Click on the link “New Repository”, follow the on-screen instruction.
Go to your Rails root directory:
git init
git add *
git commit -m “Initial commit.”
git remote add origin
git push origin master

Okay, your code is now on Github.


Make sure you have install heroku gem on your machine (gem install heroku)
Go to your Rails root directory:

== Create app

heroku create
(this will create an address for you app at
your git address will be

== Prepare for your gems

Because you can’t install gems yourself, you need to create a list of gems you need so that heroku can install them for you.
In your Rails app root directory, create a file named “.gems”. Each line of this gem will be in this format:

hpricot [–version ‘>= 0.2’] [–source]

== Deploy app

git push heroku master

This will install all gems listed in .gems, then deploy your code on Github to heroku server, and your app will run in production environment.

== Re-deploy app

When you make changes to your code, you have to push your new code to github first, then run
git push heroku master

your app will be deployed again on heroku

== Create database

heroku rake db:migrate
heroku rake db:seed


heroku rename
heroku logs


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s