What it is
The Heroku Command Line Interface (CLI) is your primary tool for interacting with the Heroku platform, managing applications, deploys, add-ons, and more.
Installation
Linux
curl https://cli-assets.heroku.com/install.sh | sh
macOS
brew install heroku/brew/heroku
If you don’t have Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install heroku/brew/heroku
Windows
Download the installer from https://devcenter.heroku.com/articles/heroku-cli and follow the instructions.
Login
After installation, log in to your Heroku account:
heroku login
This will open a browser window for authentication.
Core Concepts
- App: A deployed instance of your application on Heroku.
- Add-on: A service (like a database or cache) that can be attached to your Heroku app.
- Dyno: A lightweight virtual machine that runs your code. Heroku apps run on dynos.
- Release: A specific version of your application’s code and configuration deployed to Heroku.
- Slug: The compiled, ready-to-run version of your application code.
- Buildpack: A set of scripts and dependencies used to compile your application code.
Commands / Usage
Authentication
heroku loginAuthenticate with your Heroku account.heroku login -iAuthenticate non-interactively using email and password (useful for scripting, though API keys are preferred).heroku logoutLog out of your Heroku account.
App Management
heroku createCreate a new Heroku app.heroku create my-awesome-appCreate a new Heroku app with a specific name.heroku appsList all your Heroku apps.heroku apps --team my-teamList all apps for a specific Heroku team.heroku openOpen the current app in your default browser.heroku open -a my-awesome-appOpen a specific Heroku app in your default browser.heroku destroyDelete the current Heroku app. You will be prompted for confirmation.heroku destroy -a my-awesome-app --confirm my-awesome-appDelete a specific Heroku app without confirmation.heroku ps -a my-awesome-appList the dynos running for a specific app.heroku logs -a my-awesome-appStream the logs for a specific app.heroku config -a my-awesome-appView environment variables for a specific app.heroku domains -a my-awesome-appList custom domains for a specific app.heroku collaborators -a my-awesome-appList collaborators for a specific app.heroku members -a my-awesome-appList members of a team associated with an app.
Git Integration & Deploys
heroku git:remote -a my-awesome-appAdd the Heroku Git remote to your local repository.git push heroku mainDeploy your code to Heroku from themainbranch.git push heroku develop:mainDeploy code from your localdevelopbranch to Heroku’smainbranch.heroku releases -a my-awesome-appList all releases for a specific app.heroku releases:info <release_id> -a my-awesome-appShow details about a specific release.heroku rollback <release_number> -a my-awesome-appRoll back to a previous release number.heroku rollback v10 -a my-awesome-appRoll back to a release taggedv10.heroku buildpacks -a my-awesome-appList buildpacks for a specific app.heroku buildpacks:add heroku/nodejs -a my-awesome-appAdd a buildpack to a specific app.heroku buildpacks:remove heroku/ruby -a my-awesome-appRemove a buildpack from a specific app.heroku buildpacks:clear -a my-awesome-appClear all buildpacks from a specific app.
Add-ons
heroku addons -a my-awesome-appList all add-ons for a specific app.heroku addons:create heroku-postgresql:hobby-dev -a my-awesome-appCreate a new Heroku Postgres hobby-dev add-on for the app.heroku addons:destroy heroku-postgresql:hobby-dev -a my-awesome-appDestroy a specific add-on. You will be prompted for confirmation.heroku addons:destroy postgresql-rugged-31765 -a my-awesome-app --confirm my-awesome-appDestroy a specific add-on by its name, without confirmation.heroku addons:upgrade heroku-postgresql:standard-0 -a my-awesome-appUpgrade an existing add-on to a new plan.heroku pg:info -a my-awesome-appShow information about the PostgreSQL database attached to the app.heroku pg:credentials:url -a my-awesome-appDisplay the DATABASE_URL for the attached PostgreSQL database.
Dynos & Processes
heroku ps:scale web=2 -a my-awesome-appScale thewebprocess type to run on 2 dynos.heroku ps:scale worker=0 -a my-awesome-appScale theworkerprocess type to run on 0 dynos.heroku ps:exec -a my-awesome-appExecute a command on a running dyno.heroku ps:exec bash -a my-awesome-appOpen an interactive bash shell on a running dyno.heroku dyno:restart -a my-awesome-appRestart all dynos for the app.heroku dyno:restart web.1 -a my-awesome-appRestart a specific dyno (e.g., the first web dyno).
Config Vars (Environment Variables)
heroku config -a my-awesome-appShow all config vars for the app.heroku config:get DATABASE_URL -a my-awesome-appGet the value of a specific config var.heroku config:set API_KEY=abcdef123 -a my-awesome-appSet a new config var or update an existing one.heroku config:unset API_KEY -a my-awesome-appUnset (delete) a config var.heroku config:push -a my-awesome-appPush local config vars to Heroku (requires localheroku config:setfirst).heroku config:pull -a my-awesome-appPull Heroku config vars to your local.envfile.
Drains (Log Forwarding)
heroku drains -a my-awesome-appList log drains for the app.heroku drains:add https://my-log-service.com/logs -a my-awesome-appAdd a new log drain.heroku drains:remove https://my-log-service.com/logs -a my-awesome-appRemove a specific log drain.
SSH
heroku ssh -a my-awesome-appConnect to a running dyno via SSH.heroku ssh web.1 -a my-awesome-appConnect to a specific dyno instance via SSH.
Plugins
heroku pluginsList installed plugins.heroku plugins:install heroku-ciInstall a plugin.heroku plugins:uninstall heroku-ciUninstall a plugin.
Common Patterns
Deploying a specific branch and viewing logs
git push heroku main
heroku logs --tail -a my-awesome-app
Deploy your main branch and then continuously stream logs.
Setting multiple config vars at once
heroku config:set API_KEY=abcdef123 DATABASE_URL=postgres://user:pass@host:port/db -a my-awesome-app
Set several environment variables for your application.
Scaling dynos and checking status
heroku ps:scale web=5 -a my-awesome-app
heroku ps -a my-awesome-app
Increase the number of web dynos and then check the status of all dynos.
Rolling back a release and checking logs
heroku rollback v50 -a my-awesome-app
heroku logs --source app -a my-awesome-app
Revert to a previous release and then view logs specifically from your app’s dynos.
Adding a database and checking credentials
heroku addons:create heroku-postgresql:standard-0 -a my-awesome-app
heroku pg:credentials:url -a my-awesome-app
Provision a standard Heroku Postgres database and then get its connection URL.
Executing a command on a dyno
heroku ps:exec bash -a my-awesome-app
Open an interactive bash shell on one of your running dynos to debug.
Gotchas
heroku createnames: If you don’t specify a name, Heroku generates a random, often amusing, name (e.g.,ancient-forest-5376). Remember to use the generated name or specify your own.heroku destroyconfirmation: The--confirmflag is required to bypass the interactive prompt. Be very careful when using it, as it permanently deletes your app.git push heroku: This command deploys your code. It triggers buildpacks to compile your app. Ensure yourProcfileis correctly configured for your dyno types.- Config Vars are global: Config vars are set per app and are available to all dynos of that app. They are also sensitive, so avoid committing them directly into your code.
- Dyno Types: Be mindful of the difference between process types (e.g.,
web,worker). You scale and manage them separately.webdynos typically handle incoming HTTP requests, whileworkerdynos handle background jobs. - Add-on Names: When destroying add-ons, you can use the generic type (e.g.,
heroku-postgresql) or the specific name assigned by Heroku (e.g.,postgresql-rugged-31765). Using the specific name is safer if you have multiple instances of the same add-on type. heroku ps:exec: This command connects to one dyno. If you have multiple dynos of the same type, it picks one. Useweb.1,worker.2etc. to target specific instances.- Log Streaming:
heroku logs --tailwill keep running until you pressCtrl+C. - Local vs. Remote: Commands like
heroku config:pullandheroku config:pushhelp synchronize environment variables between your local development setup (often a.envfile) and the Heroku environment.