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

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

3 days ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

3 days ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

4 days ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

7 days ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

7 days ago

who Command in Linux: Show All Logged-In Users and Sessions

When you share a server with a team or investigate unexpected activity, the first question…

7 days ago