How to Install Git on Ubuntu 22.04

By 

Updated on

4 min read

Install Git on Ubuntu

Git is the world’s most popular distributed version control system used by many open-source and commercial projects. It allows you to collaborate on projects with fellow developers, keep track of your code changes, revert to previous stages, create branches , and more.

Git was originally developed by Linus Torvalds , the creator of the Linux kernel.

This guide covers installing and configuring Git on Ubuntu 22.04 using apt, the Git PPA, or by compiling from source.

Quick Reference

TaskCommand
Install Git (apt)sudo apt install git
Install Git (PPA)sudo add-apt-repository ppa:git-core/ppa && sudo apt install git
Check Git versiongit --version
Set usernamegit config --global user.name "Your Name"
Set emailgit config --global user.email "you@example.com"
View configgit config --list

Installing Git with Apt

This is the most convenient and quickest way to install Git on Ubuntu. If you have some special requirements and want to build Git from the source, move on to the Installing Git from the Source section of this tutorial.

Git comes preinstalled with most Ubuntu systems. Before installing Git, you can check if it is already installed on your system by typing:

Terminal
git --version

If Git is not installed on your system, the output of the command above will tell you that the command git is not found. Otherwise, it will print the installed Git version.

output
git version 2.34.1

If Git is not installed, you can install it from Ubuntu’s default repositories using the apt package manager.

Start by executing the following command as a user with sudo privileges to update the local package index:

Terminal
sudo apt update

Once the update is complete, install Git:

Terminal
sudo apt install git

You can verify the installation by checking the Git version:

Terminal
git --version

The version of Git in the Ubuntu 22.04 repositories is 2.34.1:

output
git version 2.34.1

You can now start configuring Git.

When a new version of Git is released, you can update using sudo apt update && sudo apt upgrade.

Installing Git from the PPA

The Ubuntu Git Maintainers provide a PPA with the latest stable Git releases. Use this method if you need a newer version than the default repository provides.

Add the PPA and install Git:

Terminal
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git

Verify the installation:

Terminal
git --version
output
git version 2.52.0

Installing Git from the Source

The main benefit of installing Git from source is that you can compile any Git version you want and customize the build options. However, you cannot maintain your Git installation through the apt package manager.

Start by installing the dependencies necessary to build Git on your Ubuntu system:

Terminal
sudo apt update
sudo apt install libcurl4-gnutls-dev libexpat1-dev cmake gettext libz-dev libssl-dev gcc wget

Next, open your browser and visit the Git download page . Here, you can find the latest version of Git.

Installing Git from Source

At the time of writing, the latest stable Git version is 2.52.0.

If you want to install another version of Git, click here , where you can find a list of tarballs and download the version you need.

We’re going to download the latest version and extract the Git source in the /usr/src directory, which is the common location to place source files:

Terminal
wget -c https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.52.0.tar.gz -O - | sudo tar -xz -C /usr/src

Once the download is complete, navigate to the source directory and execute the following commands to compile and install Git:

Terminal
cd /usr/src/git-*
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install

The compilation may take some time, depending on your system.

For changes to take effect on your current shell, you can either log out and log in or run the following source command:

Terminal
source /etc/environment

Verify the installation by typing:

Terminal
git --version
output
git version 2.52.0

To upgrade to a newer version later, repeat the same process with the new version number.

Configuring Git

After installing Git on your system, it is recommended that you configure your Git username and email address. Git associates your identity with every commit you make.

To set your global commit name and email address, run the following commands:

Terminal
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"

Verify the configuration changes by typing:

Terminal
git config --list

The output should look something like this:

output
user.name=Your Name
user.email=youremail@yourdomain.com

The configuration settings are stored in the ~/.gitconfig file:

~/.gitconfigconf
[user]
    name = Your Name
    email = youremail@yourdomain.com

If you want to make further changes to your Git configuration, you can either use the git config command (recommended) or edit the ~/.gitconfig file by hand.

Conclusion

We covered three ways to install Git on Ubuntu 22.04: using apt, the Git PPA for the latest version, or compiling from source.

For more information, see the Pro Git book .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page