How to Install Git on Ubuntu 24.04

How to Install Git on Ubuntu 24.04

Welcome to this tutorial on how to install Git on Ubuntu 24.04. Git is a tool that helps you keep track of changes in your files and projects, making it easier to manage your work. It’s secure and widely used by many people to organize their code and projects. While Git often comes pre-installed on Ubuntu 24.04, you might need to install a specific version yourself. This guide will take you through installing Git on your Ubuntu hosting of choice in a few simple steps.

Prerequisites:

  • An Ubuntu 24.04 VPS
  • At least 2GB of RAM
  • SSH root access or a system user with sudo privileges

Step 1. Update System Packages

To start, log in to your Ubuntu 24.04 using SSH:

ssh root@IP_Address -p Port_number

Replace ‘IP_Address’ and ‘Port_number’ with your server’s actual IP address and SSH port number. If needed, replace ‘root’ with the username of your sudo account.

Once logged in, you must make sure that all UbuntuOS packages installed on the server are up to date. You can do this by running the following commands:

apt update -y && apt upgrade -y

Method 1: Install Git on Ubuntu 24.04 Using the Package Manager

Since Git is often pre-installed on Ubuntu 24.04, you should first check if it is already installed on your system by using the following command:

git --version

The above output indicates that Git is pre-installed. If it is not installed on your system, run the following command to install Git from the official repositories:

sudo apt install git

Method 2: Install Git on Ubuntu 24.04 From the Source

If you want to install a specific version of Git on Ubuntu, you can compile it from the source. To do this, you must first install the required libraries by running the following command:

sudo apt install build-essential libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc -y

Let’s download the source code for the latest Git version, which is 2.45.2. You can replace 2.45.2 with the version you want to install:

curl -L https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.45.2.tar.gz -o git-2.45.2.tar.gz

Output:

# curl -L https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.45.2.tar.gz -o git-2.45.2.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10.6M  100 10.6M    0     0  11.1M      0 --:--:-- --:--:-- --:--:-- 11.1M

Next, extract the downloaded file using the following command:

tar -zxf git-2.45.2.tar.gz

After extracting, navigate to the Git installation folder and run the following commands:

# cd git-2.45.2/
# make prefix=/usr/local all
# make prefix=/usr/local install

Here’s how the output should look:

done && \
remote_curl_aliases="git-remote-https git-remote-ftp git-remote-ftps" && \
for p in $remote_curl_aliases; do \
        rm -f "$execdir/$p" && \
        test -n "" && \
        ln -s "git-remote-http" "$execdir/$p" || \
        { test -z "" && \
          ln "$execdir/git-remote-http" "$execdir/$p" 2>/dev/null || \
          ln -s "git-remote-http" "$execdir/$p" 2>/dev/null || \
          cp "$execdir/git-remote-http" "$execdir/$p" || exit; } \
done

After the installation finishes, verify the Git version by using the following command:

# git --version
git version 2.45.2

For additional details about Git, its features, and configuration, refer to their official documentation.

Of course, you don’t have to install Git on Ubuntu 24.04 if you use one of our Fully-Managed Git Hosting services, in which case you can simply ask our expert Linux admins to install and configure Git on Ubuntu 24.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 24.04, please share it with your friends on social networks or simply leave a comment in the comments section. Thanks

Leave a Comment