How to install Git on Ubuntu 20.04?

Overview

Git and other version control systems are crucial in present day software development. Versioning helps you to monitor all the changes made to the code of the software at every level of the development process, apart from keeping track of the changes versioning also allows you to go back to previous versions, and branch to make alternate versions of pre-existing directories and files.

Apart from all the advantages mentioned above Git made it possible for multiple developers to work on a single project supporting non-linear development, each developer has the entire copy of the source code on their local systems and any change made by them is recorded and can be reviewed before making it to the repository.

This tutorial will show you how to install and set up Git on a server running Ubuntu version 20.04.

Prerequisites

There are certain prerequisites that need to be met before you begin.

  • Ubuntu 20.04 installed or an Ubuntu 20.04 server set up.

  • User account with admin privileges.

  • Working knowledge of the Linux command line.

Get Started

If you want to set up Git and get it running quickly and are not interested in getting the latest version or functionalities this method is your best bet. This will install the most used stable version of Git. If you are interested in installing the latest version of Git move on to the subsequent section Installing Git from Source.

1. Uninstalling Older Versions

Uninstall all pre-existing older versions of Git before proceeding with the installation of the latest version of Docker.

Use the following command to remove the older versions :

sudo apt-get purge git

2. Updating the Package Repository

Use the following command to update the existing list of packages :

sudo apt update

Enter the root user password when prompted to do so.

3. Installing Git

Use the following command to install Git :

sudo apt install git

4. Checking Version and Verifying Installation

Use the following command to check the version of git installed and verify the installation :

git --version

Git has bee successfully installed.

Installing Git from Source

Although this method is a bit longer than installing from the default packages it provides you with more control over customizations and also ensures you are running the latest version of Git available at the time of installation.

Follow the steps below to install Git on Ubuntu 20.04 :

1. Uninstalling Older Versions

Uninstall all pre-existing older versions of Git before proceeding with the installation of the latest version of Docker.

Use the following command to remove the older versions :

sudo apt-get purge git

2. Updating the Package Repository

Use the following command to update the existing list of packages :

sudo apt update

Enter the root user password when prompted to do so.

3. Installing Prerequisite Packages

Use the following command to install the necessary packages :

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

4. Creating a Temporary Directory

Create a new directory to download git into and move to it by using the following commands :

mkdir gittmp; 
cd gittmp

5. Downloading Git

Go to the Git for Linux and Unix website navigate and copy the URL for the version of Git you wish to download, at the time of writing the latest version of Git for Ubuntu is 2.39.0.

Use the following command along with the copied link to download the version of git that you require :

curl -o git.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.39.0.tar.gz

Use the following command to unpack the downloaded file :

tar -zxf git.tar.gz

Use the following command to move to a new directory :

cd git-2.39.0

Use the following commands to install Git globally :

make prefix=/usr/local all;
sudo make prefix=/usr/local install

Use the following command to switch the shell process and ensure that the version of Git we installed will be used :

exec bash

6. Checking Version and Verifying Installation

Use the following command to check the version of git installed and verify the installation :

git --version

Git has been successfully installed.

Last updated