Read in 2 minutes

last updated 

How To Install Git on Ubuntu 18.04

This tutorial will guide you through the steps required to install Git on Ubuntu 18.04.

Git is a de-facto standard for distributed version control system and is used by majority of developers nowadays. It allows you to keep track of your code changes, revert to previous stages, create branches and to collaborate with your fellow developers.

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

This tutorial was tested on Ubuntu 18.04 but it should also work with any previous Ubuntu version.

Prerequisites

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

Installing Git on Ubuntu 18.04

The easiest and the recommended way to install Git is to install it using the apt package management tool from the Ubuntu’s default repositories.

Another option is to compile Git from source which will allow you to install the latest Git version and to customize the build options, but you will not able be to maintain your Git installation through the apt package manager.

Follow this steps to install Git on your Ubuntu system:

  1. Updating package index

    As always before installing new packages first update the apt package index:

    sudo apt update
  2. Installing Git on Ubuntu

    From your terminal run the following command to install Git:

    sudo apt-get install git
  3. Verifying installation

    To verify the installation type the following command to print the Git version:

    git --version
    git version 2.17.1

    At the time of the writing of this article, the current version of Gin available in the Ubuntu 18.04 repositories is 2.17.1, which is only one version behind the latest Git version (2.18.0).

  4. Configuring Git

    Now that you have git installed it is good idea to set up your personal information that will be used when you commit your code:

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

    To verify the configuration changes you can use the following command:

    git config --list
    user.name=Your Name
    [email protected]

    The configuration settings are stored in the ~/.gitconfig file:

    ~/.gitconfig
    [user]
        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 file by hand.

Conclusion

You have learned how to install Git on your Ubuntu system. You should now check the Pro Git book and learn more about how to use Git.

If you hit a problem or have a feedback, leave a comment below.