How to install Git on ubuntu 22.04

November 14, 2022 / Servers, Hosting & Email

Git is a powerful version control system used to manage software projects and track code changes. This guide explains how to install Git on Ubuntu 22.04 using either the default package manager or by compiling from source.

Prerequisites

  • A Ubuntu 22.04 system with sudo privileges.
  • An active internet connection.

Method 1: Install Git Using APT (Recommended)

This method installs Git from the official Ubuntu repositories and is the simplest and most reliable approach.

  1. To guarantee you receive the most recent version, update the package list:
    sudo apt update
  2. Install Git:
    sudo apt install git -y
  3. Verify the installation:
    git --version

    You should see output similar to: git version 2.34.1

Method 2: Install Git from Source

This method allows you to install the latest version of Git and customise features. It requires more steps and is not maintained by the package manager.

  1. Install required dependencies:
    sudo apt update
    sudo apt install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake -y
  2. Download the latest source code from the official Git repository:
    git clone https://github.com/git/git.git
  3. Change to the git directory:
    cd git
  4. Compile and install:
    make prefix=/usr/local all
    sudo make prefix=/usr/local install
  5. Verify the installation:
    git --version

Verification

After installation, confirm Git is working:

git --version

You should see the installed version number.

Next Steps
After installing Git, you can configure your user information:

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

Troubleshooting

  • If git is not found after installation, ensure /usr/local/bin is in your PATH:
    echo $PATH

    Add it to your shell profile if it’s missing.

  • For APT installation issues, run:
    sudo apt update
    sudo apt install git

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

Spread the love