How to Install Git on Ubuntu 24.04


Git is an actively maintained open-source distributed version control system used to manage changes to the computer code. It is an effective system that handles projects of different sizes and is commonly used in source code management in software development. Git is like a smart tool that keeps track of all different versions of code files. The developers use Git’s service to manage their code repositories, collaborate, and monitor small changes in the code.

On Linux systems including Ubuntu, apart from using Git for software development, you can use it to retrieve source code from the GitHub website using the git clone command. This practice is commonly used by Linux users to install applications that are unavailable in the official system repository.

In this guide, you will find:

How to Install Git on Ubuntu 24.04

You can install Git on Ubuntu 24.04 from:

How to Install Git on Ubuntu 24.04 from Apt Package Manager

The apt repository of Ubuntu 24.04 includes the Git package, allowing you to install Git on the system. However, the installed version of Git won’t be the latest one. Since Git is installed through the apt repository, you must ensure the packages are up-to-date, you can do this by running the below-given command:

sudo apt update && sudo apt upgrade -y

Once you updated the Ubuntu repository, you can install Git using:

sudo apt install git -y

After you complete the Git installation, check the Git version using the below-given command:

git --version

Note: In case you don’t want to use the Git version installed from the apt repository, you can remove it from the following command:

sudo apt remove git -y

 

How to Install Git on Ubuntu 24.04 from tar.gz Source File

If you want to install Git’s latest version on Ubuntu 24.04, you can download the tar.gz source file from GitHub and configure the files to complete the installation. Follow the steps mentioned below to perform Git installation on Ubuntu through the tar.gz source file:

Step 1: Install Dependencies on Ubuntu 24.04

Before you begin the Git installation on Ubuntu, you must install some dependencies from the following command, since they are required for smooth installation:

sudo apt install make libghc-zlib-dev libcurl4-gnutls-dev libssl-dev gettext libexpat1-dev -y

Step 2: Download Git Latest Version tar.gz Source File

Now first navigate to the Git download page and download the Git latest version tar.gz source file on Ubuntu. You can directly download the file and use the wget command, followed by the link for Git’s latest version.

When writing this blog, Git’s latest version was 2.44.0, which can be downloaded on Ubuntu using the following wget command:

wget https://github.com/git/git/archive/refs/tags/v2.44.0.tar.gz

Step 3: Extract the tar.gz Source File Content

After you download the Git source file, you must extract the file contents by using the tar command followed by the -xf flag and the source file name:

 

tar -xf v2.44.0.tar.gz

Step 4: Configure Git Installation Files

Now, navigate to Git’s source directory using the following command:

cd git-2.44.0

Then configure the Git installation files on Ubuntu by running the below-given command:

sudo make prefix=/usr/local all

Once the configuration is done, run the following command to install Git’s latest version on Ubuntu:

sudo make prefix=/usr/local install

Step 5: Check Git Version on Ubuntu

To confirm whether the latest version of Git is installed on Ubuntu, simply run the following command:

git --version

Note: If you want to remove Git from Ubuntu installed through tar.gz source, find the source directory where Git is installed, it can be done using:

which git

Then simply remove the Git source directory from Ubuntu using the below-given command:

sudo rm /usr/local/bin/git

This will remove Git from Ubuntu 24.04.

How to Configure Git on Ubuntu 24.04

After installing Git on Ubuntu 24.04, the first thing you should do is configure your Git by setting the username and email address. It is a crucial step for authorship attribution, traceability, and consistent identity, and ensures an effective tracking mechanism.

To configure Git on Ubuntu 24.04, run the following command by replacing the Git_username with your defined user:

git config --global user.name "Git_username"

Then add the email address of the username you have added using the following command by replacing [email protected] with the email address of your choice.

git config --global user.email "[email protected]"

You can then verify the Git configuration you have done by running the following command:

git config --list

These are the basic and initial things to do and to learn more about Git usage on the system, you can read the Git manual by running the following command:

man git

 

Conclusion

Git is a versatile tool that helps you manage changes to your computer code. You can install Git on Ubuntu 24.04 from the apt package manager and tar.gz source file. The apt method is simple to use and completes the Git installation with a single command. However, it doesn’t ensure installing the latest Git version on the system. The tar.gz source file method may take time, but it will install the latest version of Git on Ubuntu. Ultimately, the choice for selecting the method for Git installation on Ubuntu depends on your needs. However, you must follow the steps wisely for each method to complete the installation and configure it accordingly.

Print Friendly, PDF & Email
Categories