The Heroku CLI (Command Line Interface), also known as the Heroku Toolbelt, is essential for managing your Heroku applications. Here's how to install it on various operating systems:
brew tap heroku/brew && brew install heroku
sudo snap install --classic heroku
For Unix-based systems (excluding Windows), you can use:
curl https://cli-assets.heroku.com/install.sh | sh
For Debian/Ubuntu systems using apt-get:
curl https://cli-assets.heroku.com/install-ubuntu.sh | sh
For Arch Linux (community maintained):
yay -S heroku-cli
For users on ARM and BSD systems, or if other methods fail:
npm install -g heroku
After installation, verify that the Heroku CLI is set up correctly by checking its version:
heroku --version
To interact with your Heroku account, you need to log in:
heroku login
This command will typically open your web browser for authentication. If you prefer to stay in the command line environment:
heroku login -i
Navigate to your project directory and create a new Heroku application:
cd ~/myapp
heroku create
If you encounter login issues, try resetting your network configuration:
mv ~/.netrc ~/.netrc.backup
heroku login
You can remove the Heroku CLI using:
rm -rf /usr/local/heroku /usr/local/lib/heroku /usr/local/bin/heroku ~/.local/share/heroku ~/Library/Caches/heroku
Alternatively, if installed via Homebrew:
brew uninstall heroku
rm -rf ~/.local/share/heroku ~/Library/Caches/heroku
rm /usr/local/bin/heroku
rm -rf /usr/local/lib/heroku /usr/local/heroku
rm -rf ~/.local/share/heroku ~/.cache/heroku
sudo apt-get remove heroku heroku-toolbelt
sudo rm /etc/apt/sources.list.d/heroku.list
Heroku integrates seamlessly with Git for application deployment. Follow these steps:
cd myapp # Navigate to your project directory
git init # Initialize a new Git repository
git add -f example.json # Add specific files (even if ignored by .gitignore)
git add . # Add all project files (respecting .gitignore)
git commit -m "My first commit" # Commit your changes
Create a new application on Heroku:
heroku create appname # 'appname' is your chosen application name
Verify that the Heroku remote has been added:
git remote -v
If you have an existing Heroku app, you can add its remote:
heroku git:remote -a thawing-inlet-61413 # Replace with your app name
You can rename remotes for clarity:
git remote rename heroku heroku-staging
Push your code to Heroku:
git push heroku master # Deploy from the master branch
git push heroku master --force # Force push if needed (use with caution)
git push heroku testbranch:master # Deploy from a different local branch to Heroku's master
For SSH-based Git transport:
heroku create --ssh-git
git config --global url.ssh://[email protected]/.insteadOf https://git.heroku.com/ # Configure SSH for all Heroku repos
git config --global --remove-section url.ssh://[email protected]/ # To revert this setting
Heroku supports deploying applications packaged as Docker containers.
heroku stack:set container
heroku container:login
git clone https://github.com/heroku/alpinehelloworld.git
heroku create appname # 'appname' is your chosen application name
Build and push your Docker image:
heroku container:push web # Push the 'web' process type
heroku container:push --recursive # Push all process types recursively
heroku container:push web worker --recursive # Push 'web' and 'worker' process types recursively
Release the pushed image to your application:
heroku container:release web
Open your deployed application in a web browser:
heroku open