skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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

    1. 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).

    2. 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.

    3. Log in to Heroku:
      Open your terminal or command prompt and log in using the Heroku CLI:

      heroku login
      
    4. Create a New Heroku App or Use an Existing One:

      • To create a new app:
        heroku create your-app-name
        
      • If you already have an app, you can use the app name or URL to link it with your Git repository.
    5. Initialize Git Repository:
      If you haven’t already initialized a Git repository for your project, do so:

      git init
      

      Then, add all your files and commit:

      git add .
      git commit -m "Initial commit"
      
    6. Set the Heroku Git Remote:
      When you create a new Heroku app using the heroku create command, it automatically adds a Git remote named heroku pointing to the Heroku Git repository. If you have an existing app, you can manually set the remote:

      heroku git:remote -a your-app-name
      
    7. Deploy Your Code to Heroku:
      Push your code to Heroku using Git:

      git push heroku main
      

      Replace main with your current branch name if it is different.

    8. Manage Your App:
      Use the Heroku CLI to manage your app:

      • Scale dynos: heroku ps:scale web=1
      • Check logs: heroku logs --tail
      • Open the app in a browser: heroku open

    Summary

    • Git itself is not installed "on Heroku"; instead, you use Git locally to manage your code and deploy it to Heroku’s cloud environment.
    • Install Git and the Heroku CLI locally, log in to Heroku, initialize your Git repository, and then use Git to push your code to Heroku.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search