How to Install Git on Ubuntu 22.04

November 14, 2022 / Servers, Hosting & Email

This guide explains how to install Git on Ubuntu. Git is one of the best version control systems. Git maintains different software projects and files to enhance the sharing and collaboration of software development projects.

There are two different methods to install Git on Ubuntu-

  1. Built-in package manager
  2. Source

Let us follow the steps to install Ubuntu 22.04 using the built-in package manager-

  1. If you wish to instantly start with Git, you can opt for this method.
  2. Ubuntu 22.04 server already have Git installed on it. To confirm this, you can use the following command-
    git –version
  3. If you get the below result, then Git is already installed on your server-
    git version 2.34.1
  4. If you don’t get the output, you can install Git as given below.

How to install Git using the “Ubuntu default package manager APT”-

  1. To update the local package index, use the apt package management tools.
    sudo apt update
  2. After updating, you can install Git using the below command:
    sudo apt install git
  3. Now, to confirm the installation use the command specified below, it will also give you a relevant output:
    git –version
    git version 2.34.1

This way Git is installed successfully on Ubuntu using the default package.

How to install Git from “Source”-

Git can be built from source code if you’re searching for a more adaptable way to install it. It takes longer and is not maintained by your package manager, but you can obtain the most recent version and have more control over the features you want to add if you want to customise it.

  1. To verify the Git version installed on your server, execute the following command:
    git –version
  2. You will get the below output if Git is installed:
    git version 2.34.1
  3. At first you will have to install the software on which Git will rely. The default repositories have all of this available, allowing you to update your local package index and install the necessary packages.
    sudo apt update
    sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc
  4. You can create a temporary directory using the command after installing the software.
    mkdir tmp
  5. Go to your tmp directory and download your Git tarball there:
    cd /tmp
  6. Route to the tarball list offered at from the Git project website. Download the version you require. Utilize curl to output the downloaded file to git.tar.gz.
    curl -o git.tar.gz
  7. You can Unzip the compressed tarball file:
    tar -zxf git.tar.gz
  8. Move it to the new Git directory using the command given below:
    cd git-*
  9. Make the package using the command:
    make prefix=/usr/local all
  10. It takes some time to build. Once done, you can use the below command to install Git.
    sudo make prefix=/usr/local install
  11. Now, to use the installed version of Git, replace the shell process.
    exec bash
  12. Finally, you can check the installed version was correct.
    git –version
    git version 2.38.1

This way, Git can be installed successfully from the source.

Hope you liked our article. In our next article, you will see how to configure the installed Git version. But, if you find any difficulty in this process, you can contact our support staff at any moment.

Spread the love