Google Cloud

How to Install Git on Ubuntu 20.04

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

Git is an actively maintained open source distributed version control system designed to collaborate on projects with your developers. You can keep track of code changes, revert back, create branches, merge and more.

In this guide you are going to learn how to install Git on your Ubuntu 20.04 LTS server or system.

Prerequisites

Root access to your Ubuntu or access with sudo privileges.

There are two ways to install Git.

  1. Install Git using APT
  2. Install Git from Source

Install Git using APT

This is the easiest way to install Git on your system because Git package is included in the official Ubuntu repositories.

If you wish to install a specific version or latest stable version you need to Install Git from source.

sudo apt update
sudo apt install git

Once the installation is completed you can verify the installation using the following command.

git --version

You will get a sample output similar to the one below.

Output
git version 2.25.1

Now you can start using Git.

Install Git from Source

If you wish to install a specific version of Git or any latest stable version, you need to compile Git from source.

Make sure you install the dependencies required to install from source.

sudo apt update
sudo apt install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev make gettext libz-dev libssl-dev libghc-zlib-dev

Now choose the version you need to install and copy the tar.gz link from the official git releases page.

Git Releases

Now you can download and extract the version you wish to the /usr/share directory.

sudo wget -c https://github.com/git/git/archive/v2.28.0.tar.gz -O - | sudo tar -xz -C /usr/src

Once the download is completed you can move inside the 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 install

This will take sometime for the installation process to completed. Once completed you can check the version using the following command.

git --version

You will get a sample output similar to the one below.

Output
git version 2.28

Now you have compiled and installed Git from source.

Configure Git

Once the installation is completed you can go ahead and configure your git username and email so that Git associates your identity with every changes you make.

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Now your changes will be saved inside the ~/.gitconfig folder.

Conclusion

Now you have learned how to install Git using apt and also install Git from source.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.