How to Install Git on Ubuntu 20.04
3 min read
Git is the world’s most popular distributed version control system used by many open-source and commercial projects. It allows you to collaborate on projects with your fellow developers, keep track of your code changes, revert to previous stages, create branches , and more.
Git is originally developed by Linus Torvalds , the creator of the Linux kernel.
This guide describes how to install and configure Git on Ubuntu 20.04.
Installing Git with Apt
The Git package is included in Ubuntu’s default repositories and can be installed using the
package manager. This is the most convenient and easiest way to install Git on Ubuntu.
If you want to install the latest stable version of Git from source, move on to the Installing Git from the Source section of this tutorial.
The installation is pretty straightforward, just run the following commands as a user with sudo privileges :
sudo apt update
sudo apt install git
Verify the installation by running the following command which will print the Git version:
At the time of writing this article, the current version of Git available in the Ubuntu 20.04 repositories is
git version 2.25.1
That’s it, you have successfully installed Git on your Ubuntu, and you can start using it.
Installing Git from the Source
The main advantage of installing Git from source is that you can compile the latest Git release and customize the build options. However, you will not be able to maintain your Git installation through the
apt package manager.
Start by installing the dependencies necessary to build Git on your Ubuntu system:
sudo apt update
sudo apt install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev make gettext libz-dev libssl-dev libghc-zlib-dev
Next, open your browser, visit the Git project’s mirror on GitHub
and copy the latest release link URL that ends in
.tar.gz. At the time of writing this article, the latest stable Git version is “2.26.2”:
We’re going to download and extract
the Git source in the
/usr/src directory which is the common location to place source files:
wget -c https://github.com/git/git/archive/v2.26.2.tar.gz -O - | sudo tar -xz -C /usr/src
When the download is complete, change to the source directory and run the following commands to compile and install Git:
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
The compiling process may take a few minutes. Once done, verify the installation by running:
git version 2.26.2
Later, when you want to upgrade to a newer version of Git, use the same process.
One of the first things you need to do after installing Git is to configure your git username and email address. Git associate your identity with every commit you make.
To set your global commit name and email address run the following commands:
git config --global user.name "Your Name"
git config --global user.email "firstname.lastname@example.org"
You can verify the configuration changes, by typing:
git config --list
The output should look something like this:
user.name=Your Name email@example.com
The configuration settings are stored in the
[user] name = Your Name email = firstname.lastname@example.org
If you want to make further changes to your Git configuration, you can either use the
git config command (recommended) or edit the
~/.gitconfig file by hand.
Installing Git on Ubuntu is a matter of running a single
apt command. If you want to use the latest Git release, you can compile it from the source.
To learn more about Git, Visit the Pro Git book website.
If you hit a problem or have feedback, leave a comment below.