How to Install Git on Ubuntu 22.04

how to install git on ubuntu 22.04

Git is a free and open-source distributed version control system; it outclasses the other version control tools such as SCM Subversion, CVS, Perforce, and ClearCase. Git is used to tracking source code changes, enabling multiple developers to work together on non-linear development. Unlike most client–server systems, every Git directory on every system is a repository with complete history and full version-tracking abilities.

Git is also used in popular platforms for code management and version control, such as Github, Gitlab, Bitbucket, and others. Today we will show you how you can install Git using the apt package manager and how to install git from Source; let’s start.

Step 1. Log in to your server

First, log in to your Ubuntu 22.04 VPS through SSH as the root user:

ssh root@IP_Address -p Port_number

Replace “root” with a user with sudo privileges or root if necessary. Additionally, replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port number. Next, let’s make sure that we’re on Ubuntu 22.04. You can execute the following command.

# lsb_release -a

You should get this as the output:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy

Step 2. Update the system

Before starting, we need to make sure that all Ubuntu 22.04 packages installed on the server are up to date. You can do this by executing the following commands:

# apt update -y

Step 3. Install git

The Ubuntu 22.04 OS should have the git package installed by default on your system. In any case, you can check if you have git installed by running the following command from your terminal:

 # git --version
 git version 2.34.1

If you already have git installed on your system, this command will display the version of git you currently have installed on your system.
In our case, we have git version 2.34.1 installed; depending on the time of reading this post, the git versions may vary.

If the git package is not installed, we can install it with the following commands:

 # apt update
 # apt install git

You will need to enter ‘Y’ to continue the installation, which will install the git package on the system.

If you want to check if the installation was successful or which git version you have installed on your system, you can run the git –version command again.

Sometimes you may want to install a different git version. To check which git version are available to install with apt, you can use the following command:

 # apt-cache policy git

You should receive output similar to this:

git:
Installed: (none)
Candidate: 1:2.34.1-1ubuntu1.5
Version table:
1:2.34.1-1ubuntu1.5 500
500 http://us.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages
100 /var/lib/dpkg/status
1:2.34.1-1ubuntu1 500
500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages

Install git from Source

Installing a newer or different version of git can be done by installing git from the source.

First, you should update the package sources list with the latest versions of the packages in the repositories with apt update and install all the dependencies needed for the git software to run.

 # apt update
 # apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc

Next, you can choose which git version you want to install from the following link https://mirrors.edge.kernel.org/pub/software/scm/git/

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

Once you choose the version you want to install, we will download the package with:

 # wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz

Then you should unpack the compressed tarball file:

 # tar -xzf git-2.9.5.tar.gz

Next move to the git-2.9.5 directory:

 # cd git-2.9.5

And then, to install git you should run the following commands:

 # make prefix=/usr/local all
 # make prefix=/usr/local install
 # exec bash

To check if the installation was completed, you can run the command:

 # git --version

Of course, you don’t have to install git on Ubuntu 22.04 if you use one of our VPS Hosting services, in which case you can simply ask our expert Linux admins to install git on Ubuntu 22.04 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on installing git on Ubuntu 22.04, please share it with your friends on social networks or simply leave a comment in the comments section. Thanks.

Leave a Comment