Heroku applications are created and administered from the command line. To get started with Heroku, we need to install the Heroku Toolbelt. It contains everything we need to create and deploy new applications.
The toolbelt is an installer for three command-line tools:
In this recipe, we will install the Heroku Toolbelt, making sure our machine is set up to use the Heroku CLI. We'll also be briefly introduced to the Heroku CLI. We'll learn about Git and Foreman later in the chapter.
Note
If you already have the Heroku Toolbelt, it might be beneficial to go through the following steps again to ensure that the latest version is installed.
First, we need to create a Heroku account with the following steps:
Let's go to www.heroku.com and create an account if we do not already have one.
Next, let's install the Heroku Toolbelt. Specific download and installation instructions are available at https://toolbelt.heroku.com/ for Mac, Windows, and Linux.
Once the Heroku Toolbelt is installed, we can verify that everything is working by opening up a terminal and running the following command:
$ heroku --version heroku-toolbelt/3.11.1 (x86_64-darwin10.8.0) ruby/1.9.3
We should see the version of the Heroku Toolbelt we are using printed to the console.
Now that we have the Heroku Toolbelt installed, let's log in to our account via the CLI and authorize our computer by uploading our public key using the following steps:
Let's log in by opening up a terminal and running the following command:
$ heroku login Username: [email protected] Password (typing will be hidden): Could not find an existing public key.Would you like to generate one? [Yn]Generating new SSH public key.Uploading ssh public key /Users/mc/.ssh/id_rsa.pub
If we do not have an existing public key, the Heroku CLI will provide us with instructions on how to create one here. This key will be uploaded to Heroku's servers and used for authentication whenever we push new code to our applications.
We can ensure that we are authenticated with the
auth:whoami
command. If logged in successfully, it will print our e-mail address:$ heroku auth:whoami [email protected]
Finally, we should go to the Heroku dashboard and verify our account by adding a credit card. Having a verified account will allow us to scale our applications and install add-ons (https://dashboard.heroku.com/account).
The Heroku Toolbelt installs all the necessary tools to create and administer our Heroku applications. It's essential for us to become comfortable with Heroku's command-line tools. Even though many tasks can be completed on Heroku's website, not everything is available through the dashboard. For full control over our applications, we have to use the CLI.
Ever wondered how Heroku keeps us logged in to the CLI? During the login process, Heroku stores an API key for our account in our .netrc
file. The .netrc
file is a dotfile that lives in our home directory. It's a common file that applications use to store credentials to log in to remote hosts. The API key stored in this file is used for subsequent logins and keeps us logged in to our Heroku account. If we open our .netrc
file, we'll see an entry for api.heroku.com. If we ever run the auth:logout
command, it deletes the entry from our .netrc
file, thus logging us out.
Interested in seeing the source code for the Heroku CLI? It's open source; take a look at https://github.com/heroku/heroku.