How to install and setup git on Ubuntu

Git is a popular version control system widely used by coders to keep track of their codes and collaborate with other team members working on the same project. Linus Torvalds, who is the inventor of the Linux kernel, has developed Git. It helps to manage any type of project by creating branches, tracking the change of the code, and reverting to the previous stage of the code. How Git can be installed and used on Ubuntu has been shown in this tutorial.


Before starting the installation of Git, you have to update the system by running the following command.

$ sudo apt update

Install Git using apt:

One way to install Git is to use the apt command. It is the easiest way to install Git on Ubuntu. Run the following command from the terminal to install the Git. You have to provide the root password to start the installation process.

$ sudo apt install git

The following similar output will appear after executing the command, and you have to wait for some time to complete the installation process.

After installing Git successfully, run the following command to check the installed version of Git.

$ git --version

The following output shows that git version 2.27.09 has been installed in the system by using the `apt` command.

Install Git from a source:

Installing Git by using the `apt` command has two disadvantages. The user will not be able to maintain the Git installation, and the `apt` package manager does not install the latest version of Git. You have to download the Git package from any particular source and install it later to use the updated version of Git. You can download the Git package in any location of the system. Suppose you want to download the package under the/usr/temp folder. temp folder does not exist by default. Run the following commands, create the temp folder under /usr folder and go to the folder. You will require root privilege to create any folder under /usr folder.

$ sudo mkdir /usr/ temp
$ cd /usr/temp

Go to the following URL to get the list of all Git packages. You can select the latest version from the list.


The git-2.29.3.tar.xz package contained the latest version of Git when this tutorial was written. You can down the package manually or run the following command to download the package in the current location.

$ sudo curl -o git.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.29.3.tar.xz

Run the `ls` command to check the package is downloaded properly or not.

$ ls

The following output will appear after executing the above command.

Run the following command to extract the compressed, check the Git installation folder is created or not, and go to that installation folder.

$ sudo tar -xf git.tar.gz
$ ls
$ cd git-2.29.3

The following output shows that the downloaded package has been extracted properly, and you can start the installation process now.

Before installing the Git, you have to remove the previously installed Git package and then install the required git dependencies for the new installation. Run the following command to remove the Git from the system if you installed it before. It will ask for the root privilege if you have not given it before and ask to press ‘y’ to start the removal process.

$ sudo apt remove git

Run the following command to install the Git dependencies.

$ sudo apt install libcurl4-openssl-dev libssl-dev

If the above packages are installed properly, run the following two commands to compile and install Git.

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

Run the following command to replace the shell process to use the installed version of Git.

$ exec bash

After executing the above all commands successfully, run the following command again to check the installed version of the Git.

$ git --version

The following output shows that the installed version of Git is 2.29.3, an updated version of the previously installed Git.

Setup the Git:

After installing the required version of Git using `apt` or from a particular source, you have to set up the necessary configurations to use the Git. The proper configuration will help the Git user to generate commit messages and built any project properly using Git.

The `git config` command is used to set the configuration for Git. The most common configuration is to set the name and email of the user. You can check the configuration values from the terminal or by opening the ~/.gitconfig in any editor. Run the following commands to set the git user’s name and email and display the values of the git configuration from the terminal.

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

The following output shows that “Fahmida” has been set as the name of the git user, and “[email protected],com” has been set as the email address of the git user. The other configuration parameters show the default values.

You can edit the git configuration by opening the file, ~/.gitconfig file in any editor. Here, the nano editor is used to open the file. Run the following command from the terminal to open the ~/.gitconfig file in nano editor and check or update the existing configuration values of the git.

$ nano ~/.gitconfig

According to the above configuration, the following information will be displayed in the editor.


The git is a useful package for the software development task when the developers mainly work in a team. Two ways to install Git on Ubuntu and the way to set up the configuration of git to use it have been explained in this tutorial. After reading this tutorial, I hope the readers will be able to install Git on Ubuntu and set it up properly to use it for their project.

About the author

Fahmida Yesmin

I am a trainer of web programming courses. I like to write article or tutorial on various IT topics. I have a YouTube channel where many types of tutorials based on Ubuntu, Windows, Word, Excel, WordPress, Magento, Laravel etc. are published: Tutorials4u Help.