Installing Git on RHEL 9 or Rocky Linux 9: A Comprehensive Guide

Git stands as a cornerstone version control system, essential for managing source code changes across various domains like development, DevOps, and system administration. This guide provides a walkthrough for installing Git on RHEL 9 or Rocky Linux 9, catering to both development environment setups and project-specific needs.

Prerequisites

Before proceeding, ensure the following:

  • A system running RHEL 9 or Rocky Linux 9.

  • Sudo or root privileges for software package installation.

  • Internet connectivity.

Method 2: Installing Git on RHEL 9 or Rocky Linux 9 from Source

Installing Git from source lets you obtain the latest version, or a specific version. This is useful if the version in the default package manager is outdated.

Step 1: Install Development tools

Before building Git from source, install the necessary development tools using the following dnf command:

$ sudo dnf groupinstall 'Development Tools' -y

It will install the development tools required to build git from the source.

Step 2: Install other required dependencies using beneath command

$ sudo dnf install wget curl-devel perl-ExtUtils-MakeMaker gettext openssl-devel zlib-devel curl-devel expat-devel -y

Step 3: Download the Latest Git Source Code

Visit Kernel.org to find the latest version, or download directly:

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

Note: At the time of writing this post, the latest version of Git is 2.47.0. Adjust the version number in the command if a newer version is available.

Step 4: Extract the Downloaded Archive

Extract the tar file:

$ tar -xf git-2.47.0.tar.gz
$ cd git-2.47.0

Step 5: Compile and Install Git

Compile the Git source code with these commands:

$ make configure
$ ./configure --prefix=/usr
$ sudo make all
$ sudo make install

Step 6: Verify the Installation

Verify the installed Git version:

$ git --version

This should display the installed Git version.

Method 1: Installing Git on RHEL 9 or Rocky Linux 9 Via DNF

The easiest method to install Git on RHEL 9 or Rocky Linux 9 is using the dnf package manager.

Step 1: Update Your System

Update your system packages to the latest versions:

$ sudo dnf update -y

Step 2: Install Git

Install Git using the following dnf command:

$ sudo dnf install git -y

Step 3: Verify the Installation

Check if Git was installed successfully by verifying the version:

$ git --version

This command should output the installed Git version.

Configuring Git on RHEL 9 | Rocky Linux 9

After installing Git, configure your username and email address for commit attribution.

Step 1: Set Your Username

$ git config --global user.name "Your Name"

Step 2: Set Your Email Address

$ git config --global user.email "your.email@example.com"

Step 3: Verify the Configuration

Verify your Git configuration:

$ git config --list

This command will display your configured username and email.


This guide covered installing Git on RHEL 9 and Rocky Linux 9 using both the package manager and source code methods. Remember to configure your Git username and email for proper commit attribution.