Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
Hide categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Developer Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Troubleshooting Node.js Apps
      • Working with Node.js
      • Node.js Behavior in Heroku
    • Ruby
      • Rails Support
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • PHP Behavior in Heroku
      • Working with PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Vector Database
    • Working with AI
    • Heroku Inference
      • AI Models
      • Inference Essentials
      • Inference API
      • Quick Start Guides
    • Model Context Protocol
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Developer Tools
  • Command Line
  • Running Apps Locally

Running Apps Locally

English — 日本語に切り替える

Last updated January 31, 2025

Table of Contents

  • Run Your App Locally with the Heroku Local Command-Line Tool
  • Set Up Your Local Environment Variables
  • Copy Heroku Config Vars to Your Local .env File
  • Run Your App Locally Using Foreman
  • Run Your Cloud Native Buildpack App Locally Using Pack

This article explains how to use the Heroku Local CLI plugin.

Run Your App Locally with the Heroku Local Command-Line Tool

Heroku Local is a command-line tool to run Procfile-backed apps. It’s installed automatically as part of the Heroku CLI. Heroku Local reads configuration variables from a .env file. Heroku Local uses node-foreman to accomplish its tasks.

Start Your App Locally

To start all the process types defined in your Procfile, enter:

$ heroku local

heroku local is a shorter alternative to heroku local:start.

To start a particular process type, specify the process type. For example, web or worker.

$ heroku local web

You can now test the app locally. Press Ctrl+C to shut it down when you’re done.

Here are some of the command line options.

  • To use a different Procfile, use the -f flag: heroku local -f Procfile.test.

  • To use a different environment file, use the -e flag: heroku local -e .env.test.

  • To use a different port, use the -p flag: heroku local -p 7000. If you don’t specify a port, 5006 is used.

For more information, enter heroku help local at the command line.

Run a One-Off Command Locally

With Heroku Local, you can run a single one-off command locally. For example: heroku local:run rails console. This command is analogous to Heroku’s one-off dynos.

Set Up Your Local Environment Variables

When running your app, typically you use a set of config vars to capture the app’s configuration. For example, say your app uses S3 for image storage. You want to store the credentials to S3 as config vars. If you run your app locally, you want to use a different S3 bucket than if you run it in production.

With the .env file, you can capture all the config vars you need to run your app locally. When you start your app using any of the heroku local commands, the .env file is read, and each name/value pair is inserted into the environment, to mimic the action of config vars.

View Your App’s Config Vars

To view all your app’s config vars, enter heroku config.

Look at the Contents of Your .env File

$ cat .env

Here’s an example .env file.

S3_KEY=mykey
S3_SECRET=mysecret

Add a Config Var to Your .env File

Don’t commit credentials and other sensitive configuration values to source control. In Git, exclude the .env file with echo .env >> .gitignore.

To add a config var to your .env file, edit it and add a new name=value pair on a new line.

Copy Heroku Config Vars to Your Local .env File

Sometimes you want to use the same config var in local and Heroku environments. For each config var that you want to add to your .env file, use this command.

$ heroku config:get CONFIG-VAR-NAME -s  >> .env

Don’t commit the .env file to source control. Only use it for local configuration. Update your .gitignore file to exclude the .env file.

Keep in mind that your deployed production app can connect to different services than your local development app. For example, your deployed production app can have a DATABASE_URL config var that references a Heroku Postgres database, but your local app has a DATABASE_URL variable in the .env file that references your local installation of Postgres.

Run Your App Locally Using Foreman

As an alternative to using Heroku Local, you can use Foreman to run your app locally. It’s not officially supported, but if you want to use it, you can get more information by visiting the Foreman GitHub repository.

Foreman is a command-line tool for running Procfile-backed apps. Foreman reads configuration variables from a .env file.

Start Your App Locally

$ foreman start
18:06:23 web.1     | started with pid 47219
18:06:23 worker.1  | started with pid 47220
18:06:25 worker.1  | (in /Users/adam/myapp)
18:06:27 web.1     | => Awesome web application server output

If you had a Procfile with web and worker process types, Foreman starts one of each process type, with the output interleaved on your terminal. Your web process loads on port 5000 because this is what Foreman provides as a default in the $PORT env var. It’s important that your web process respects this value because the Heroku platform uses it when you deploy.

You can now test the app locally. Press Ctrl+C to shut it down when you are done.

Alternatively, you can select a different environment file at launch with the -e flag. For example: foreman -e alternate_env start.

Run a One-Off Command Locally

You can run a single one-off command locally with Foreman. For example: foreman run rails console. This command is analogous to Heroku’s one-off dynos.

Run Your Cloud Native Buildpack App Locally Using Pack

As an alternative to using Heroku Local, apps using the cnb stack can use pack to run locally. Pack is a CLI tools maintained by the Cloud Native Buildpack project that can build applications using buildpacks into runnable OCI images.

You must install a OCI runtime like Docker when working with Cloud Native Buildpacks locally.

Build Your App into an OCI image

To produce an OCI image from your app using pack, you must run pack build. To produce the same image that Heroku builds for your app when you deploy, use the heroku/builder:24 build image.

pack build <your-image-name> \
  --builder heroku/builder:24 \
  --path .

Replace <your-image-name> with an identifier of your choosing.

Run the App Image

After creating the OCI image for your app, you can run it in Docker (or any alternative OCI runtime). For example, using docker run:

docker run \
  --publish 5006:5006 \
  --env PORT=5006 \
  --env-file ./.env \
  --rm --interactive --tty <your-image-name>

Replace <your-image-name> with the identifier from the previous build step.

docker run starts the app’s web process in a Docker container. The --publish 5006:5006 binds port 5006 of the container to port 5006 of the host so you can access your app locally. You must also set the --env PORT=5006 so that your web process knows which container port to bind to when it starts.

Running Commands

You can run other commands using your app’s Docker image. For example, to execute bash:

docker run \
  --publish 5006:5006 \
  --env PORT=5006 \
  --entrypoint launcher \
  --rm --interactive --tty node-getting-started bash

Replace <your-image-name> with the identifier from the previous build step.

Keep reading

  • Command Line

Feedback

Log in to submit feedback.

Using CLI Plugins The Heroku CLI

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices