How To

Install Git on Ubuntu 20.04: Apt, Source, and Configuration

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:

  • Track every change made to your project files over time
  • Collaborate with other developers without overwriting their work
  • Create branches to work on new features without touching the main code
  • Roll back to any previous version of your codebase at any time

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.

Method 1: Install Git on Ubuntu with Apt

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.

Method 2: Install Git from Source

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.

Configure Git After Installation

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>&nbsp;If you work with multiple Git accounts (personal and work), you can set per-repository settings using&nbsp;<code>git config</code>&nbsp;without the&nbsp;<code>--global</code>&nbsp;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.

Cyber Defence

Recent Posts

Install MySQL on Ubuntu 20.04: Setup, Security, and Root Access

MySQL is the most popular open-source relational database management system. It is fast, reliable, and a…

41 minutes ago

Install Go on Ubuntu 20.04: Download, Setup, and First Program

Go (also called Golang) is an open-source programming language built by Google. It is designed to…

56 minutes ago

Install VS Code on Ubuntu 20.04: Snap Package and Apt Guide

Visual Studio Code (VS Code) is an open-source code editor developed by Microsoft. It is one…

1 hour ago

Install Nginx on Ubuntu 20.04: Setup, Firewall, and Config Guide

Nginx (pronounced "engine x") is an open-source, high-performance web server and reverse proxy. It is used…

1 hour ago

Install Apache on Ubuntu 20.04: Setup and Virtual Host Guide

Apache is one of the most widely used open-source web servers in the world. It is…

1 day ago

Add Swap Space on Ubuntu 20.04: Create, Enable, and Tune

Swap space is an area on disk that Linux uses when it runs out of physical…

1 day ago