• 2 hours
  • Medium

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 9/4/18

Log in or subscribe for free to enjoy all this course has to offer!

Course introduction

Welcome to this course on Heroku!  Let's learn about what it is and how it can help you as a Ruby developer.

What is Heroku? 

Heroku is a  cloud service that allows users to deploy multiple applications onto their platform.

Is it expensive? 

It costs nothing to set up a Heroku account and you can deploy as many applications as you want. Heroku pricing is based on a measure of computing resources the company calls a “dyno.” Think of a dyno as a virtual server (though it is not). For personal projects, you can run your Rails application on a single dyno and never incur a charge, as long as it is not active more than 12 hours a day. If you have a busy website, however, you will likely need to upgrade your hosting.

A single dyno idles after one hour of inactivity. In other words, it “goes to sleep” until it receives a new web request. For a personal project, this means your web application will respond with a few seconds delay if it hasn’t received a web request in over an hour. After it wakes up, it will respond quickly to every browser request.

Adaptability and Version Control

Heroku embraces the languages of many modern applications - this includes but is not limited to - Java, Ruby, PHP, and Node.

Languages!
Languages!

Heroku aims to be scalable, enabling you to increase the size and usage of your application without having to worry about manually setting up a server and hardware yourself.

The Heroku platform uses Git Version control as the primary means for deploying applications. When you create an application on Heroku, it associates a new Git remote, typically named heroku, with the local Git repository for your application.

As a result, deploying code is just the familiar git push, but to the Heroku remote endpoint instead.  Let's take a look at how to do that.

Deploy a Ruby on Rails application with Heroku

 Step 1: Create a user account for Heroku here.

Be sure to use the same email address you used to configure Git locally. You can check the email address you used for git with: git config --get user.email 

Step 2: You’ll need the special Heroku CLI (Command Line Interface) for your OS found here.

After installation, you’ll have access to the  $ heroku  command in your CLI. Log in using the email address and password you used when creating your Heroku account:  heroku login

Step 3: Check your versions

You’ll need a minimum of Rails 5 as well as Ruby version 2.20 and above to work with Heroku.  In addition to that you’ll need to be using Postgres as your database.

  • Make sure you’re on the right version with  rails -v

  • To upgrade:  gem install rails --no-ri  --no-rdoc 

  • Make sure you’re on a valid ruby version with  ruby -v

 Step 4:  Make sure your database is using postgres in your Gemfile

Change gem "sqlite3" to gem "pg." Make sure the adapter in your config/database.yml file is set to postgresql.

Step 5: Generate a new Gemfile.lock and re-install your new dependencies with bundle install.

 Step 6: Use git with Heroku

Verify you have Git installed  git --help 

Step 7: Navigate to your application inside of the CLI. 

Step 8: Initiate Git and make your first commit. 

  1. Git init  (tells git the current folder is going to be tracked)

  2. Git add   (adds all files in the folder to be tracked)

  3. Git commit -m "initial commit"  (Saves the current point in code)

  4. Git status

Step 9: Deploy!

  1. heroku create

  2. git push heroku master

  3. heroku run rake db:migrate

Step 10: Visit your site!

  1. heroku ps:scale web=1

  2. heroku open

Congratulations!

You've just deployed your first application with Heroku!

Example of certificate of achievement
Example of certificate of achievement