Git is the most widely used version control system in the world. It was created by Linus Torvalds, the developer behind the Linux kernel. Today it powers almost every software project, from small open-source tools to large enterprise platforms.
With Git, you can:
This guide shows you how to install Git on Ubuntu 20.04 using apt or by compiling from source, and how to set up your commit identity.
Prerequisite: You need sudo access to follow these steps.
This is the easiest way to install Git. The apt package manager handles everything for you.
Run these two commands:
bashsudo apt updatesudo apt install git
Verify the installation:
bashgit --version
The version available in Ubuntu 20.04 repositories is 2.25.1. This version is stable and works well for most development workflows. If you need the absolute latest release, use Method 2 below.
git version 2.25.1
That is it. Git is installed and ready to use.
Installing from source gives you the latest Git release, which may be newer than what is available in Ubuntu’s repositories. The trade-off is that you manage updates manually — apt will not handle them for you.
Start by installing the build dependencies:
bashsudo apt updatesudo apt install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev make gettext libz-dev libssl-dev libghc-zlib-dev
Go to the Git releases page on GitHub and find the latest .tar.gz URL. Download and extract it to /usr/src:
bashwget -c https://github.com/git/git/archive/v2.26.2.tar.gz -O - | sudo tar -xz -C /usr/src
Move into the source directory and compile Git:
bashcd /usr/src/git-*sudo make prefix=/usr/local allsudo make prefix=/usr/local install
This takes a few minutes. Once done, verify the version:
bashgit --version
Output:
git version 2.26.2
When a newer Git version comes out, repeat these steps with the updated URL.
Before you start working with Git, set your username and email. Git attaches this identity to every commit you make.
Set your global username and email:
bashgit config --global user.name "Your Name"git config --global user.email "youremail@yourdomain.com"
Verify the settings are saved:
bashgit config --list
Output:
user.name=Your Nameuser.email=youremail@yourdomain.com
Git stores this in the ~/.gitconfig file. You can edit that file directly, but using the git config command is the cleaner approach and less error-prone.
<strong>Tip:</strong> If you work with multiple Git accounts (personal and work), you can set per-repository settings using <code>git config</code> without the <code>--global</code> flag. The local setting will take priority over the global one.
To see all available options, run git config --help. It lists every setting you can configure for your local or global Git setup.
Git is now installed and configured on your Ubuntu system. You can start cloning repositories, making commits, and collaborating right away. To go deeper, the Pro Git book is free online and covers everything from the basics to advanced branching and workflows. Got questions? Leave a comment below.
MySQL is the most popular open-source relational database management system. It is fast, reliable, and a…
Go (also called Golang) is an open-source programming language built by Google. It is designed to…
Visual Studio Code (VS Code) is an open-source code editor developed by Microsoft. It is one…
Nginx (pronounced "engine x") is an open-source, high-performance web server and reverse proxy. It is used…
Apache is one of the most widely used open-source web servers in the world. It is…
Swap space is an area on disk that Linux uses when it runs out of physical…