Website Vidya
Cloud & DevOpsStep-by-Step Guide

How to Install Git on Ubuntu 24.04 LTS

Learn how to install git on ubuntu 24.04 LTS via official APT repositories, the Git maintainers PPA, source compilation, and Git configuration.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
PDF Cheat Sheet
How to Install Git on Ubuntu 24.04 LTS
AI Executive SummaryWebsiteVidya AI

5 min read

Learn how to install git on ubuntu 24.04 LTS via official APT repositories, the Git maintainers PPA, source compilation, and Git configuration.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Checking for an Existing Git Installation
  • Step 2: Method 1: Installing Git via Default APT Repositories
Grounded in full engineering runbookWebsiteVidya AI Engine

Git is the industry-standard distributed version control system (DVCS) that underpins modern collaborative software engineering, CI/CD deployment pipelines, and open-source ecosystems.

Engineered by Linus Torvalds for high performance, non-linear development, and cryptographic integrity, Git allows teams to track changes, maintain feature branches, and merge code seamlessly.

Whether you are building web applications, maintaining system administration scripts, or orchestrating cloud infrastructure, Git is the first tool you must configure on any development environment.

In this guide, we walk through how to install git on ubuntu 24.04 LTS using default Ubuntu repositories, installing cutting-edge releases via the Git Maintainers PPA, compiling from source, and configuring user credentials.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A computer or server running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
  • A user account with sudo administrative privileges.
  • Access to a command-line terminal shell.

Step 1: Checking for an Existing Git Installation

Before installing Git, check whether a version is already installed on your system.

Advertisement

Run the git --version command in your terminal:

If Git is already installed, the command outputs the release version; if not, your shell prompts you with installation instructions:

# Check installed Git version:
git --version
# If installed: git version 2.43.0
# If missing: Command 'git' not found, but can be installed with...

Step 2: Method 1: Installing Git via Default APT Repositories

The fastest and most stable method for installing Git on Ubuntu is using the official APT repository.

Ubuntu 24.04 provides a well-tested, rock-solid release of Git directly in its main software component.

Advertisement

Update your local repository cache and install the git package:

# Update APT package lists:
sudo apt update

# Install Git via APT:
sudo apt install -y git

# Verify installed Git version and executable path:
git --version
which git
# Output confirms: /usr/bin/git

Step 3: Method 2: Installing Latest Git via the Git Maintainers PPA

While Ubuntu's default repository package is stable, it remains frozen at the version shipped during the initial Ubuntu release.

If you require the absolute latest upstream features, bug fixes, or performance enhancements, install Git from the official Git Core PPA maintained directly by the Ubuntu Git packaging team.

Add the PPA to your system and install the upgraded package:

# Install software-properties-common if missing:
sudo apt install -y software-properties-common

# Add the official Git Core Team PPA:
sudo add-apt-repository -y ppa:git-core/ppa

# Refresh repository cache and upgrade Git:
sudo apt update
sudo apt install -y git

# Confirm that Git was updated to the latest upstream release:
git --version

Step 4: Method 3: Compiling Git from Source Code

Compiling Git from source provides total control over build configurations, allows you to link specific cryptographic libraries, and ensures you have the latest commit directly from the developers.

First, install the necessary compilation build tools and development libraries:

Download the source tarball from GitHub or kernel.org, compile, and install it into /usr/local:

# Install source compilation dependencies:
sudo apt update
sudo apt install -y make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev \
  libexpat1-dev gettext unzip build-essential

# Download desired Git release tarball:
cd /tmp
wget https://github.com/git/git/archive/refs/tags/v2.45.0.tar.gz -O git.tar.gz
tar -xf git.tar.gz
cd git-2.45.0

# Compile and install Git:
make prefix=/usr/local all -j $(nproc)
sudo make prefix=/usr/local install

# Verify newly compiled binary:
/usr/local/bin/git --version

Step 5: Configuring Git User Identity and Global Defaults

After installing Git, configure your name and email address before committing any code.

Git embeds this information immutably into every commit you create, ensuring auditability across codebases.

Use the git config command to set your global user parameters and configure modern defaults like the default main branch:

# Configure global user name and email:
git config --global user.name "Rajesh Rai"
git config --global user.email "[email protected]"

# Set default initial branch name to main:
git config --global init.defaultBranch main

# Configure preferred text editor (e.g., nano or vim):
git config --global core.editor nano

# Review all active global Git configurations:
git config --list --show-origin

Step 6: Generating SSH Keys for GitHub and GitLab Authentication

Major code hosting platforms—including GitHub, GitLab, and Bitbucket—require SSH key authentication or personal access tokens rather than plaintext account passwords.

Generate a secure Ed25519 SSH key pair using ssh-keygen:

Display your public key and paste it into your GitHub or GitLab SSH Settings:

# Generate an Ed25519 SSH key pair:
ssh-keygen -t ed25519 -C "[email protected]"
# Press Enter to accept default location (~/.ssh/id_ed25519)

# Start ssh-agent and register your private key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# Display public key to copy to your GitHub/GitLab account:
cat ~/.ssh/id_ed25519.pub

# Test connection to GitHub:
ssh -T [email protected]
# Expected confirmation: Hi username! You've successfully authenticated...

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

git: command not found

Cause: Git is not installed on the system, or /usr/bin is missing from the shell $PATH.

Resolution: Install Git via APT: sudo apt update && sudo apt install -y git.

sudo apt update && sudo apt install -y git

fatal: unable to auto-detect email address (got 'user@hostname')

Cause: Attempting to create a git commit before configuring user.name and user.email.

Resolution: Configure your global user identity: git config --global user.name 'Name' and git config --global user.email '[email protected]'.

git config --global user.name "Your Name" && git config --global user.email "[email protected]"

Permission denied (publickey) when pushing to GitHub/GitLab

Cause: Your SSH public key is not added to your hosting account, or the ssh-agent is not running.

Resolution: Add your ~/.ssh/id_ed25519.pub key to your account settings and verify with ssh -vT [email protected].

ssh -T [email protected]

Security Best Practices and Hardening

Protect your SSH private keys (~/.ssh/id_ed25519) with a strong passphrase and never share or commit private keys to repositories.

Enable commit signature verification using GPG or SSH keys (git config --global commit.gpgsign true) to guarantee author authenticity.

Never store plaintext API tokens or database passwords inside Git repositories; use environment variables or secret managers.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
For standard production servers, the official Ubuntu repository package is recommended because it receives tested security patches. For developers who want the latest Git features and branch enhancements, the official ppa:git-core/ppa is the best choice.
Git stores global configurations in ~/.gitconfig (or ~/.config/git/config), system-wide configurations in /etc/gitconfig, and repository-specific settings in .git/config.
Run git config --list --show-origin to see all applied configuration directives and the exact files they are defined in.
Ed25519 is a modern elliptic-curve public-key signature system that offers superior cryptographic security, faster computation, and significantly shorter key lengths compared to legacy RSA keys.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Cloud & DevOps•

How to Close File Descriptors Above 9 in Dash Shell

Attempting to close a file descriptor above 9 in Dash using exec 10<&- results in a 10: not found error because Dash's POSIX lexer only recognizes single-digit file descriptors (0–9) in redirection operators. This guide explains the exact parser limitation, why FDs 10+ are reserved for internal shell state, and how to safely close inherited file descriptors using close_range, Python, or Perl wrappers.

RR
Rajesh Rai
Read More
Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout