Over a million developers have joined DZone.

Deploying a Sinatra App to Heroku

· Cloud Zone

Download the Essential Cloud Buyer’s Guide to learn important factors to consider before selecting a provider as well as buying criteria to help you make the best decision for your infrastructure needs, brought to you in partnership with Internap.

Heroku is a cloud application platform that is designed to take the worry out of server administration. You just build your app, push it to Heroku via Git, and relax. What about deploying a Sinatra app though? Let’s see…

If you followed along with my post about building a data driven app with Sinatra you might be ready to try a deployment. Since Sinatra is a Ruby app, deployment it not quite as straightforward as say, a PHP app, but it’s still not hard.

Getting started with Sinatra…

If you are just starting out with Sinatra, you may find this post useful. If you are coming to Sinatra from PHP, I wrote an article for Rubysource that shows you how to build a blog app with Sinatra.

You will need a (free) account at Heroku.

Assuming that you are happy with your app locally, the next thing to do is make sure you have a couple of files:

  1. Gemfile
  2. config.ru

The Gemfile I described in the post above includes references to all the Ruby gems used in the app:

source :rubygems
gem 'sinatra'
gem 'rdiscount'
gem 'data_mapper'
gem 'dm-migrations'
gem 'pony'
gem 'dm-postgres-adapter', :group => :production
gem 'dm-sqlite-adapter', :group => :development
group :production do
  gem 'pg', '0.14.1'

You may not need some of these: rdiscount, and Pony for example. I’ll discuss those in a later post. Take note of the groups for production and development. Heroku doesn’t support Sqlite.


Sinatra is a Rack app, but Heroku has no problems with those. We just need a file to explain how we want our app to run:

In config.ru you need the following:

require './main'
run Sinatra::Application

You deploy to Heroku via Git, the source code management system. You can initialise a Git repository from the command line:

git init

Install the Heroku Gem

You will also need the Heroku gem:

gem install heroku

SSH Keys

You will need to create SSH keys. You can learn how to do that here

While you are on the command line, you will need to connect your keys to Heroku for secure communication between your computer at Heroku:

heroku keys:add

You’ll be asked to add the credentials that you created your Heroku account with.

Create the Heroku App

Back on the command line do:
heroku create nameofapp

Where nameofapp is what ever name you want for your app, bearing in mind that that Heroku will create your app with a url like this: nameofapp.herokuapp.com.

Then, assuming that you have committed your latest updates, you can do:

git push heroku master

You’ll see Heroku receive the push, compress files, install the Ruby gems needed, and then, with any luck, deploy your app.

All you need to do now, is continue to develop your app, commit, and the Git push to Heroku to deploy.


The Cloud Zone is brought to you in partnership with Internap. Read Bare-Metal Cloud 101 to learn about bare-metal cloud and how it has emerged as a way to complement virtualized services.


Published at DZone with permission of Andy Hawthorne, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}