How to install Git on Ubuntu 18.04

s2 0

Git is a de facto standard for distributed version control systems and is used by most developers today. It allows you to track your code changes, go back to previous phases, create branches, and collaborate with your fellow developers.

Git was originally developed by Linus Torvalds
, the creator of the Linux kernel.

This tutorial will walk you through the steps required to install Git on Ubuntu 18.04. The same instructions apply to Ubuntu 16.04 and any other Ubuntu-based distribution, including Kubuntu, Linux Mint, and Elementary OS.


Before proceeding with this tutorial, make sure you are logged in as root or a user with sudo privileges.

Install Git with apt

The easiest and most recommended method of installing Git is to install it with the apt
Package management tool from the standard Ubuntu repositories. If you want to install the latest stable version of Git from source, go to that Install Git from the source
Section of this tutorial.

Follow these steps to install Git on your Ubuntu system:

  1. Start by updating the package index:

    sudo apt update
  2. Run the following command to install Git:

    sudo apt install git
  3. Verify the installation by entering the following command that prints the Git version:

    git --version

    At the time of this writing, the most current version of Git available in the Ubuntu 18.04 repositories is 2.17.1.

    git version 2.17.1

That’s it, you’ve successfully installed Git on your Ubuntu and you’re ready to use it.

Install Git from the source

Another option is to compile Git from source, which allows you to install the latest version of Git and customize the build options. However, you cannot use the apt Package manager.

First, install the dependencies needed to build Git on your Ubuntu system:

sudo apt updatesudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

Once the installation is complete, open your browser, visit the Mirror of the Git project on GitHub
and copy and paste the latest release link url that ends on .tar.gz:

At the time of this writing, it is the latest stable version of Git 2.23.0.

We’ll download the git source in the /usr/src Directory, which is the general storage location for source files, change to the directory with:

cd /usr/src/

Download the file as a git.tar.gz Use the link copied earlier:

sudo wget -O git.tar.gz

Next, unzip the tar.gz file and change to the Git source directory by typing:

sudo tar -xf git.tar.gzcd git-*

Run the following two commands to compile and install Git on your Ubuntu system:

sudo make prefix=/usr/local allsudo make prefix=/usr/local install

To verify the installation, enter the following command which will output the installed Git version:

git --version
git version 2.23.0

If you want to upgrade to a newer version, you have to repeat the installation process.

Git. configure

Now that you’ve installed Git, it’s a good idea to set up your personal information that will be used when you commit your code.

The following commands set your git commit username and email address:

git config --global "Your Name"git config --global "[email protected]"

Enter the following to review the configuration changes:

git config --list

The output should look something like this: Name
[email protected]

The configuration settings are saved in ~/.gitconfig File:

~ / .gitconfig
    name = Your Name
    email = [email protected]

If you want to make further changes to your Git configuration, you can either use the git config Command or edit the ~/.gitconfig put down by hand.


Installing Git on Ubuntu is a matter of running a single apt Command. If you want to use the latest version of Git, you need to compile it from source.

You should check now Per Git book
and learn more about using Git.

If you run into any problem or have any feedback, please leave a comment below.