How to Install Git on Ubuntu 22.04

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
| Task | Command |
|---|---|
| Install Git (apt) | sudo apt install git |
| Install Git (PPA) | sudo add-apt-repository ppa:git-core/ppa && sudo apt install git |
| Check Git version | git --version |
| Set username | git config --global user.name "Your Name" |
| Set email | git config --global user.email "you@example.com" |
| View config | git 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:
git --versionIf 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.
git version 2.34.1If 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:
sudo apt updateOnce the update is complete, install Git:
sudo apt install gitYou can verify the installation by checking the Git version:
git --versionThe version of Git in the Ubuntu 22.04 repositories is 2.34.1:
git version 2.34.1You 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:
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install gitVerify the installation:
git --versiongit version 2.52.0Installing 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:
sudo apt update
sudo apt install libcurl4-gnutls-dev libexpat1-dev cmake gettext libz-dev libssl-dev gcc wgetNext, open your browser and visit the Git download page . Here, you can find the latest version of Git.

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:
wget -c https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.52.0.tar.gz -O - | sudo tar -xz -C /usr/srcOnce the download is complete, navigate to the source directory and execute the following commands to compile and install Git:
cd /usr/src/git-*
sudo make prefix=/usr/local all
sudo make prefix=/usr/local installThe 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:
source /etc/environmentVerify the installation by typing:
git --versiongit version 2.52.0To 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:
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"Verify the configuration changes by typing:
git config --listThe output should look something like this:
user.name=Your Name
user.email=youremail@yourdomain.comThe configuration settings are stored in the ~/.gitconfig file:
[user]
name = Your Name
email = youremail@yourdomain.comIf 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 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