I need my web app in Heroku to have git
installed (I’m on the heroku-24
stack). I’m trying to use heroku-community/apt. I created Aptfile
with the following content (found it here):
https://launchpad.net/~git-core/+archive/ubuntu/ppa/+files/git-all_2.46.0-0ppa1~ubuntu20.04.1_all.deb
Then, I added the buildpack:
$ heroku buildpacks:add --index 1 heroku-community/apt
=== zerocracy Buildpack URLs
1. heroku-community/apt
2. heroku/ruby
During the deployment, I see this log:
remote: -----> Building on the Heroku-24 stack
remote: -----> Using buildpacks:
remote: 1. heroku-community/apt
remote: 2. heroku/ruby
remote: -----> Apt app detected
remote: -----> Detected Aptfile or Stack changes, flushing cache
remote: -----> Updating APT package index
remote: Get:1 http://archive.ubuntu.com/ubuntu noble InRelease [256 kB]
remote: Get:2 http://archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
remote: Get:3 http://archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
remote: Get:4 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages [1,808 kB]
remote: Get:5 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
remote: Get:6 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages [19.3 MB]
remote: Get:7 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [594 kB]
remote: Get:8 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [449 kB]
remote: Get:9 http://archive.ubuntu.com/ubuntu noble-backports/universe amd64 Packages [11.5 kB]
remote: Get:10 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages [337 kB]
remote: Get:11 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages [404 kB]
remote: Get:12 https://apt.postgresql.org/pub/repos/apt noble-pgdg InRelease [129 kB]
remote: Get:13 https://apt.postgresql.org/pub/repos/apt noble-pgdg/main amd64 Packages [476 kB]
remote: rm: cannot remove '/var/cache/apt/archives/partial/*.deb': Permission denied
remote: Fetched 24.2 MB in 2s (13.3 MB/s)
remote: Reading package lists...
remote: -----> Fetching https://launchpad.net/~git-core/+archive/ubuntu/ppa/+files/git-all_2.46.0-0ppa1~ubuntu20.04.1_all.deb
remote: -----> Installing git-all_2.46.0-0ppa1~ubuntu20.04.1_all.deb
remote: -----> Writing profile script
remote: -----> Rewrite package-config files
remote: -----> Ruby app detected
...
However, git
is not available:
+ git --version
sh: 1: git: not found
2
Answers
We can not install git inside Heroku platform. You can only deploy the app via git to Heroku. If you really need to install git inside the app you must need to try something like using infrastructure services like AWS EC2 or AWS Elastic Beanstalk.
To install Git on Heroku, you actually don’t need to "install" Git on the Heroku platform itself. Heroku’s environment doesn’t provide persistent storage or the ability to install software directly like a traditional server. However, here is what you can do to use Git with Heroku effectively:
Steps to Use Git with Heroku
Install Git Locally: Ensure Git is installed on your local machine. You can download Git from git-scm.com. Installation steps vary depending on your operating system (Windows, macOS, Linux).
Install the Heroku CLI: The Heroku Command Line Interface (CLI) is a tool that allows you to manage Heroku apps from the terminal. You can download and install it from the official Heroku Dev Center.
Log in to Heroku:
Open your terminal or command prompt and log in using the Heroku CLI:
Create a New Heroku App or Use an Existing One:
Initialize Git Repository:
If you haven’t already initialized a Git repository for your project, do so:
Then, add all your files and commit:
Set the Heroku Git Remote:
When you create a new Heroku app using the
heroku create
command, it automatically adds a Git remote namedheroku
pointing to the Heroku Git repository. If you have an existing app, you can manually set the remote:Deploy Your Code to Heroku:
Push your code to Heroku using Git:
Replace
main
with your current branch name if it is different.Manage Your App:
Use the Heroku CLI to manage your app:
heroku ps:scale web=1
heroku logs --tail
heroku open
Summary