How to Install Git on Rocky Linux EL9 or EL8

Git is a widely-used open-source distributed version control system that has become essential for developers. Known for its speed and efficiency in managing projects, Git offers a range of features that set it apart from other version control systems. This guide aims to provide you with step-by-step instructions on how to install Git on Rocky Linux 9 or its older stable release based on Enterprise Linux 8.

Key Features of Git

  • Distributed System: Unlike centralized version control systems, Git allows each computer to serve as a full-fledged repository. This enables complete history and version tracking without network access or a central server.
  • Branching and Merging: One of Git’s standout features is its robust branching model. It allows for quick and easy creation, merging, and deletion of multiple local branches, making the development process more efficient.
  • Speed and Efficiency: Git is built for speed. It can manage large projects effortlessly and is generally faster than other version control systems.
  • Data Integrity: Git ensures the security and integrity of your data by using a data model that checksums every file and commit. This means you can be confident that your data remains secure and unaltered.

The upcoming guide will walk you through installing Git on Rocky Linux 9 or its older stable release based on Enterprise Linux 8. This will enable you to fully utilize Git’s capabilities on a secure, high-performance operating system.

Section 1: Install Git on Rocky Linux

This section will walk you through installing Git on Rocky Linux. Git is a distributed version control system that allows multiple people to work on a project simultaneously without overwriting each other’s changes. It’s an essential tool for any developer, and installing it on your Rocky Linux system is straightforward.

Step 1: Updating Rocky Linux Before Git Installation

Before we begin the installation process, ensuring that your system is up-to-date is important. This is to ensure that all existing packages on your system are at their latest versions, which can help prevent potential conflicts and ensure the smooth running of new installations. You can update your system by running the following command in the terminal:

sudo dnf upgrade --refresh

This command will refresh your system’s package list and upgrade all installed packages to their latest versions.

Step 2: Choosing the GIT Installation Method on Rocky Linux

There are two main methods for installing Git on Rocky Linux: using the default Appstream or manually compiling from source code. We’ll go through both methods in this guide.

Option 1: Installing Git with Default Appstream on Rocky Linux

One of the benefits of using Rocky Linux is that Git is included as a default package. This means that it’s always up-to-date and ready to use, simplifying the installation process. To install Git using the default Appstream, run the following command in the terminal:

sudo dnf install git

This command will install Git on your system using the default package manager.

Option 2: Install GIT via Manual Archive Download on Rocky Linux

If you need a specific version of Git that’s unavailable through the package manager, or if you want to install Git with custom configurations, you can compile it from source code.

First, visit the official Git website’s release page to find the latest stable version or the specific version you need. Once you’ve identified the version you want, you can download it using the wget command in the terminal. This command fetches the Git source code from the official repository and prepares it for compilation.

For example, to download Git version 2.39.2, you would use the following command:

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

Please note that Git releases new versions frequently, so checking the official website regularly is important to keep your Git installation up-to-date.

Once you’ve downloaded the source code, you can extract it using the tar command:

tar -xzf git-x.x.x.tar.gz

Next, navigate to the directory containing the extracted source code:

cd git-x.x.x

Before you start the compilation process, installing the development tools is recommended. This will ensure that nearly all the required dependencies are installed. You can do this by running the following command:

sudo dnf groupinstall "Development Tools"

A few dependencies aren’t included in the development tools pack. You can install these by running the following command:

sudo dnf install libcurl-devel expat-devel

Now you’re ready to configure the script. Run the make command in the terminal:

make prefix=/usr/local all

Finally, install Git by running the following command:

sudo make prefix=/usr/local install

You can confirm the version of Git that’s currently installed on your system by running the git --version command in the terminal. This will display the version number of the Git installation on your

git --version

Section 2: Git Configuration & Setup on Rocky Linux

In this section, we will delve into the configuration and setup of Git. After installing Git, it’s important to configure it properly to ensure smooth operation. We will also cover some typical commands that Git users use daily.

Step 1: Adding a User to Git

After installing Git, the first thing you need to do is set up your user details. These details, including your name and email, are used mainly in git commit messages. Here’s how to set them up:

git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL"

Replace “YOUR NAME” and “YOUR EMAIL” with your name and email. If you prefer, you can use a pseudonym and a fake email.

Step 2: Creating a Directory for Git

If you want to create a new directory specifically for Git, you can do so using the mkdir command:

mkdir example-directory -p

Then, navigate to the newly created directory:

cd example-directory

Next, initialize the directory as a Git repository using the git init command:

git init

This command creates a hidden .git directory that stores the repository’s configuration, history, and other data. You can view the contents of this directory using the ls -a .git command.

Step 3: Printing Git Config Details

To confirm your Git configuration details, use the git config --list command:

git config --list

Git stores these details in the ~/.gitconfig file by default. You can view the contents of this file using the cat command:

cat ~/.gitconfig

Step 4: Storing Git Credentials

If you want to store your authorization details, you can enable the credential helper cache:

git config --global credential.helper cache

For security reasons, it’s recommended to cache your credentials only for a limited time. For example, if you plan to work with Git for 1 to 4 hours and then not use it for a few weeks, you can set the cache to expire after 5 hours:

git config --global credential.helper "cache --timeout=18000"

After 5 hours, your credentials will be deleted from the cache, enhancing the security of your Git setup.

Step 5: Checking the Git Repository Status

To view the status of your Git repository, use the git status command:

git status

This command provides information about the current state of your repository, including any changes made.

Step 6: Connecting to a Remote Git Repository

If you need to work with a remote Git repository, you must link your local repository to it. This can be done using the git remote command:

git remote add origin remote-repository-link

Replace “remote-repository-link” with the URL of the remote repository.

Step 7: Committing Changes in Git

When you’ve made changes in your Git repository and want to save them, you can use the git commit command:

git commit -m "git message changelog"

The -m "git message changelog" part of the command is the message that will appear in the changelog. It should describe the changes you’ve made.

Step 8: Pushing Changes to a Remote Repository

After committing your changes, you might want to share them with others by pushing them to a remote repository. The git push command allows you to do this:

git push origin master

This command pushes your changes from your local “master” branch to the “master” branch of the remote repository named “origin”.

Step 9: Pulling Changes from a Remote GIT Repository

Your teammates might also push their changes to the remote repository in a collaborative environment. To incorporate these changes into your local repository, you can use the git pull command:

git pull origin master

This command fetches the changes from the “master” branch of the remote repository named “origin” and merges them into your current local branch.

Final Thoughts on Installing Git on Rocky Linux

In this comprehensive guide, we’ve walked through setting up GIT on Rocky Linux, a robust, community-driven enterprise operating system. We’ve covered the essential steps from configuring your GIT user profile to creating and managing your GIT directories. We’ve also delved into the crucial aspects of storing GIT credentials securely, checking your GIT repository status, and working with remote repositories. By mastering these fundamental GIT commands, you can manage your code effectively, collaborate with others, and maintain a robust version control system for your projects.

Leave a Comment