How to deploy application to online server using Heroku

By:, On:

This tutorial assumes you have already completed:

  1. Install Ruby on Rails
  2. Create Ruby on Rails application
  3. Create Static Pages - without this deploy will not work
  4. Install Git
  5. Create Remote Git Repository - optional but recommended

Our simple application is now working. It's now time to make it work on the internet so that other people can access it. Back in the day, this was a difficult process. Today, thanks to companies like Heroku it has become very, very simple. It takes just a couple simple steps to deploy the app to the Heroku platform.

Our application is prepared to work in 3 different configurations: Test, Development and Production. The test environment is a special configuration that runs special scripts. These scripts checks to ensure the application is working in the right order. Development is what we can access when we run $rails consoleor $rails server and open a browser with the address http://localhost:3000. Production is a special configuration for the server. All environments are using different databases and we can make them use different email addresses, etc.

For our production environment, we will be using the platform. Not only can we host our application for free there (until we generate reasonable traffic) but also everything is ready to go. After the initial setup, deploying an application will be as easy as typing a simple command in the Terminal. Let's get going:

Step 1: Create an Account on Heroku

Head over to and create an account there.

After you confirm your account head back to to download the Heroku toolbelt.

Step 2: Heroku Login

After you install it, open terminal and type:



heroku login

Enter your credentials:

Enter your Heroku credentials.
Could not find an existing public key.
Would you like to generate one? [Yn]
Generating new SSH public key.
Uploading ssh public key /Users/adam/.ssh/

Step 3: Configure the Database

First, we need to make sure we use the proper type of database for our production environment. Rails, by default, gave us an SQLite3 database, which is okay for our development environment. Heroku however wants us to use PostgreSQL database. Let's make sure our Gemfile has the necessary gems.



# Use sqlite3 as the database for Active Record
gem 'sqlite3'


group :development, :test do
  gem 'sqlite3'
group :production do
  gem 'pg'

Because the way heroku uses Gemfile.lock file to build our application we will need to delete that file now, and rebuild it with command "bundle install". Otherwise, heroku will reject our push. So go ahead and delete Gemfile.lock. It's next to the Gemfile.

Step 4: Install dependencies

Now, we can install all the new dependencies. In your terminal, type:


$ bundle install

Step 5: Change Configuration File

One more change we need to make is to change the configuration file for our database. Head over to config/database.yml:


# SQLite version 3.x
#   gem install sqlite3
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
  <<: *default
  database: db/test.sqlite3

  adapter: postgresql
  host: localhost
  pool: 5
  timeout: 5000
  database: demo_production

Note that we have changed the settings for the production database.

Step 6: Changes to Git Repository

We can now commit the changes to the git repository:

$ git add .
$ git commit -m "changed database type for production to postgres"

Step 7: Deploy application to Heroku

At this point, we are ready to deploy our application to Heroku. First, we have to create an application:

$ heroku create pick-unique-name-of-your-application
Creating peoplecancode-demo... done, stack is cedar |

If the creation is successful, you will be able to deploy the application to Heroku:

$ git push heroku master
Fetching repository, done.
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 970 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.5.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Using rake (10.3.1)
       Using json (1.8.1)
       Using i18n (0.6.9)
       Using thread_safe (0.3.3)
       Using builder (3.2.2)
       Using erubis (2.7.0)
       Using minitest (5.3.3)
       Using rack (1.5.2)
       Using polyglot (0.3.4)
       Using mime-types (1.25.1)
       Using arel (
       Using bcrypt (3.1.7)
       Using coffee-script-source (1.7.0)
       Using execjs (2.0.2)
       Using thor (0.19.1)
       Using orm_adapter (0.5.0)
       Using hike (1.2.3)
       Using multi_json (1.9.3)
       Using pg (0.17.1)
       Using bundler (1.5.2)
       Using tilt (1.4.1)
       Using sass (3.2.19)
       Using rdoc (4.1.1)
       Using tzinfo (1.1.0)
       Using treetop (1.4.15)
       Using rack-test (0.6.2)
       Using warden (1.2.3)
       Using uglifier (2.5.0)
       Using sprockets (2.11.0)
       Using coffee-script (2.2.0)
       Using sdoc (0.4.0)
       Using activesupport (4.1.0)
       Using mail (2.5.4)
       Using actionview (4.1.0)
       Using activemodel (4.1.0)
       Using jbuilder (2.0.6)
       Using activerecord (4.1.0)
       Using actionpack (4.1.0)
       Using actionmailer (4.1.0)
       Using railties (4.1.0)
       Using sprockets-rails (2.1.3)
       Using coffee-rails (4.0.1)
       Using devise (3.2.4)
       Using rails (4.1.0)
       Using jquery-rails (3.1.0)
       Using sass-rails (4.0.3)
       Using turbolinks (2.2.2)
       Your bundle is complete!
       Gems in the groups development and test were not installed.
       It was installed into ./vendor/bundle
       Bundle completed (0.58s)
       Cleaning up the bundler cache.
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       Asset precompilation completed (2.05s)
       Cleaning assets
       Running: rake assets:clean
-----> WARNINGS:
       Include 'rails_12factor' gem to enable all platform features
       See for more information.

       You have not declared a Ruby version in your Gemfile.
       To set your Ruby version add this line to your Gemfile:
       ruby '2.0.0'
       # See for more information.

       No Profile detected, using the default web server (webrick)
-----> Discovering process types
       Procfile declares types -> (none)
       Default types for Ruby  -> console, rake, web, worker

-----> Compressing... done, 21.5MB
-----> Launching... done, v9 deployed to Heroku

   e8bbe97..6f47150  master -> master

The second to last line shows you your URL. Open it in your browser. Your app is now on the internet. Please share the link in the comments :-)

If you login you will be able to mark this tutorial as finished to track your progress


  • On: Frank wrote:

    Great! Got it up and online!
  • On: Philip Lohrmann wrote:

    Problem! I tried a second app from the beginning in case there was some mistake, but still no good. When ever I do .... Replace Gemfile # Use sqlite3 as the database for Active Record gem 'sqlite3' With with group :development, :text do gem 'sqlite3', end gem 'pg', group: :production and then invoke the command "bundle install" I get the error : "Gemfile syntax error on line 8: syntax error, unexpected keyword_end" (line 8 is: "end") So I delete, "end" on line and re-invoke "bundle install"; I get: Gemfile syntax error on line 8: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' gem 'pg', group: :production ^ on line 8: syntax error, unexpected ',', expecting keyword_end gem 'pg', group: :production I delete "," and then it runs a bunch of stuff, success(?) but towards the end: "Gem::Ext::BuildError: ERROR: Failed to build gem native extension." and some other stuff that sounds like bad news, and finally: "extconf failed, exit code 1 Gem files will remain installed in /Users/plohmav/.rvm/gems/ruby-2.1.2/gems/pg-0.17.1 for inspection. Results logged to /Users/plohmav/.rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/pg-0.17.1/gem_make.out An error occurred while installing pg (0.17.1), and Bundler cannot continue. Make sure that `gem install pg -v '0.17.1'` succeeds before bundling." What should I do here?
  • On: Michael Lajlev wrote:

    There is a bit of typos: This: group :development, :text do gem 'sqlite3', end gem 'pg', group: :production should be replaced with this: group :development, :test do gem 'sqlite3' end gem 'pg', group: :production
  • On: Fabiola Cabrera wrote:

    Thank you! We just fixed it!
  • On: Fabiola Cabrera wrote:

    Thank you! We just fixed it!
  • On: Brunitob wrote:

    Greetings from Argentina! -- I had some problem running bundle install with pg on mac I solved ->
  • On: Marius wrote:

    thanks. that helped. thanks a lot

  • On: Almas Kairatuly wrote:

    Many thanks!!! you saved me days!))

  • On: silvina wrote:

    Hello: thank you for the wonderful tutorial and my issue is with heroku. I had an account from long ago and this is the error i get silvinas-MacBook-Pro:static formsmama$ git push heroku master fatal: '' does not appear to be a git repository fatal: Could not read from remote repository.

    Please make sure you have the correct access rights and the repository exists.

    I did add the new ssh key to heroku but the error still there.

  • On: silvina wrote:

    Do we have to perform the configuration change every time we create a new project?

  • On: Brayan López wrote:


You can login to comment