How to Install Git on Ubuntu 18.04

The easiest way for installing Git on your computer is visiting the page Git downloads and choosing download for Linux where the latest stable upstream Git version is provided. Also, read how to Install Git on Mac and on Windows.

Install Git from Repository

First step is to open a terminal window.

  1. Copy and paste the following into the terminal window and hit Enter. You may be prompted to enter your password. With the update complete, you can download and install Git:
    sudo apt update
    sudo apt-get install git
  2. To confirm that you have installed Git correctly run the following command:
    git --version

    The output will be like this:

    git version 2.17.0
  3. Now it’s time to set your personal information. Enter the following commands to add your name and email:
    git config --global "W3docs"
    git config --global [email protected]
  4. As you configure the reference into Git, you can open a Git configuration file where you will come up with the user details like this:
    [ .. ]
              [email protected]
    [ .. ]

The version you install via these repositories may be older than the newest version currently available. If you need the latest release, consider the next method.

Install Git from Source

In case you wish to install the latest git version you will have to install Git from the source code.

Compiling the software from source is a more flexible method for installing Git. This method will take longer time, but it will allow you to download the latest release and will give you some control over the options.

  1. Before you start, you have to install the software that Git depends on. So you can update your local package index and then install the packages.
    sudo apt update
    sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
  2. Next, by visiting the Git Source Code Mirror choose the version of Git you want.
  3. Choose "master" branch then click on the "Tags" list and select your preferred Git version.

    Avoid choosing release candidate (RC) versions, because they may have an unstable nature.

  4. Then, click on "Clone or download" which will open a new window. Right-click on "Download ZIP" and choose "Copy link address."

  5. After that, go back to your terminal, set the wget command for downloading Git zip package using the copied link download address. It will be like this:
  6. Unzip the file that you downloaded and move into the resulting directory with the following command:
    cd git-2.19.0
  7. Now you are ready to install Git. Follow these two commands which will compile the formerly downloaded git source code and will install git binaries on your Ubuntu 18.04 Linux system.
    make prefix=/usr/local all
    sudo make prefix=/usr/local install
  8. To confirm that you have installed Git successfully run the following command:
    git --version

You will get an output like this:

git version 2.19.0

Now it’s time to set up Git and provide user information by using the git config command:

git config --global "W3docs"
git config --global ""

The result will be like this:
[email protected]

If you want to see all the configuration items that have been set previously, use the git config command with the --list option. And if you want to change the details you provided, change the settings by editing the main .gitconfig git configuration file located within your home directory.