Easy Steps To Install Latest Git on AlmaLinux 8 – OrcaCore

Posted on

Easy Steps To Install Latest Git on AlmaLinux 8 - OrcaCore

Easy Steps To Install Latest Git on AlmaLinux 8 – OrcaCore

This tutorial aims to guide you on How To Install Latest Git on AlmaLinux 8. Git is a DevOps tool used for source code management. It’s a free and open-source version control system designed to handle projects of all sizes efficiently. Git is crucial for tracking changes in source code, enabling multiple developers to collaborate on non-linear development projects. Linus Torvalds created Git in 2005 specifically for the development of the Linux kernel.

Follow the steps below to set up the latest version of Git on AlmaLinux 8.

To complete this guide, you must log in to your server as a non-root user with sudo privileges. You can refer to the guide on Initial Server Setup with AlmaLinux 8 for instructions on doing so.

1. Download and Install Git From Source

Git packages are available in the default AlmaLinux repository. However, this guide focuses on installing the latest version of Git.

First, update your local package index with the following command:

sudo dnf update -y

Next, install the required packages and dependencies using this command:

sudo dnf install gettext-devel curl-devel expat-devel openssl-devel perl-CPAN perl-devel zlib-devel unzip cmake gcc make wget -y

Now, visit the Git Release page to find the master zip archive or the latest stable release of Git.

Download the latest Git version on AlmaLinux 8 using the wget command:

wget https://github.com/git/git/archive/refs/tags/v2.37.3.zip

After the download is complete, unzip the file with the command below:

sudo unzip v2.37.3.zip

Switch to the Git directory:

cd git-2.37.3

Now, use the following commands to install Git:

# sudo make prefix=/usr/local all
# sudo make prefix=/usr/local install

Once the installation is complete, verify your Git installation on AlmaLinux 8 by checking its version:

git --version
**Output**
git version 2.37.3

2. Set up and Configure Git on AlmaLinux 8

Now, configure Git to ensure that the commit messages you generate contain accurate information, supporting your software project’s development.

You need to provide your name and email address because Git embeds this information into each commit you make. Use the following commands to do this:

# git config --global user.name "Your Name"
# git config --global user.email "youremail@domain.com"

After setting up the user name and email ID, you can verify the details using the git config --list command:

git config --list
git config list

All configurations done through the git command save the information in a file called .gitconfig in the user’s home directory. You can also verify the configuration by checking this file using the cat ~/.gitconfig command, as shown below:

cat ~/.gitconfig
verify git configuration

3. Testing Git with Git Clone Command

Now that you have set up Git on AlmaLinux 8, you can test it by performing git clone operations from GitHub.

Clone a repository called "wig" by using the following command. This will create a directory wig in your local system and copy all the contents from the repository:

git clone https://github.com/jekyc/wig.git
Testing Git with Git Clone Command

You can also check all the subcommands available with the git command using the git help -a command:

git help -a

To check the git status, use the command below:

git status

Conclusion

You have now learned How To Install Latest Git on AlmaLinux 8. Installing the latest Git on AlmaLinux 8 involves either enabling the EPEL and PowerTools repositories or building from source. Using dnf install git provides the default version, but compiling from source ensures access to the newest features and fixes.

Hope you enjoyed it. You may also like these articles:

Alternative Solutions for Installing Git on AlmaLinux 8

While the article details installing Git from source, here are two alternative methods that can simplify the process and potentially provide more streamlined updates:

1. Using Software Collections (SCL)

Software Collections allow you to install multiple versions of the same software on a single system without causing conflicts. This is beneficial if you need a newer version of Git than what’s provided in the base AlmaLinux 8 repositories, but you don’t want to replace the system-provided version. This method is useful because it isolates the new Git version, preventing potential compatibility issues with other system tools.

  • Explanation: SCL packages are installed in /opt/rh/<collection_name>/root/usr/bin, allowing you to enable them only when needed using the scl command. This keeps your system clean and manageable.

  • Steps:

    1. Install the centos-release-scl package: This provides access to the SCL repositories.

      sudo dnf install centos-release-scl -y
    2. Search for available Git collections: This lists the available Git versions within the SCL. The specific collection name might vary depending on the available packages.

      sudo dnf --enablerepo=centos-sclo-rh-* list available git

      Look for a package like rh-git231. Replace rh-git231 with the actual package name if it differs.

    3. Install the desired Git collection: This installs the specific Git version within the SCL environment.

      sudo dnf install rh-git231 -y
    4. Enable the Git collection: Before using the SCL-installed Git, you need to enable it in your current shell session.

      scl enable rh-git231 bash

      This command opens a new shell session with the SCL environment enabled. Git version within this shell will be the one installed from SCL.

    5. Verify the Git version: Confirm that the correct Git version is active in the enabled shell.

      git --version
    6. To use the SCL Git in scripts or non-interactive sessions: You can use the scl enable command within your scripts. For example:

      #!/bin/bash
      source /opt/rh/rh-git231/enable
      git --version
      # Your Git commands here

2. Using a Custom Repository

Another option is to add a custom repository that provides newer Git packages. This is a more advanced method, but it can provide access to very recent or even development versions of Git. Be cautious when using repositories from untrusted sources, as they may contain malicious software or unstable packages.

  • Explanation: This involves adding a new repository configuration file to your system’s DNF configuration directory (/etc/yum.repos.d/). This file tells DNF where to find the Git packages.

  • Steps (Example using a theoretical, but be very careful using a repo from the internet!):

    1. Find a suitable repository: Search online for AlmaLinux 8 repositories that offer newer Git packages. Ensure the repository is reputable and maintained. Be extremely cautious about trusting third-party repositories. Verify their security and trustworthiness before adding them to your system. For demonstration purposes only, let’s assume a repository exists at https://example.com/almalinux/8/git/.

    2. Create a repository configuration file: Create a new file in /etc/yum.repos.d/ (e.g., git-custom.repo) with the following content (adjust the URL and other details to match the actual repository):

      [git-custom]
      name=Custom Git Repository for AlmaLinux 8
      baseurl=https://example.com/almalinux/8/git/
      enabled=1
      gpgcheck=0  # DO NOT DISABLE GPG CHECK unless you fully trust the source!
      #gpgkey=https://example.com/almalinux/8/git/RPM-GPG-KEY  # Uncomment and adjust if the repo provides a GPG key

      Important Security Note: gpgcheck=0 disables GPG signature verification. This is highly discouraged unless you completely trust the repository and are aware of the security risks. If the repository provides a GPG key, download it and specify its URL in the gpgkey option, and set gpgcheck=1.

    3. Clean the DNF cache: This ensures that DNF recognizes the new repository.

      sudo dnf clean all
    4. Enable the PowerTools repository (if needed): Some dependencies might be in the PowerTools repository.

      sudo dnf config-manager --set-enabled powertools
    5. Install Git: DNF should now install Git from the custom repository.

      sudo dnf install git -y
    6. Verify the Git version: Confirm that the installed Git version is from the custom repository.

      git --version

Caveats and Considerations:

  • Security: Always prioritize security. Verify the integrity and trustworthiness of any repository or software collection you use. Use GPG key verification whenever possible.
  • Dependencies: Be aware that installing Git from a custom repository or SCL might require installing additional dependencies. The dnf command should handle these automatically, but be prepared to troubleshoot dependency issues if they arise.
  • Stability: Newer versions of Git might introduce bugs or compatibility issues. Test thoroughly after upgrading to ensure that your workflow is not affected.
  • System Updates: Installing Git outside the default repositories might interfere with system updates. Be mindful of this when updating your system and be prepared to resolve any conflicts.

These alternative solutions offer different ways to install latest Git on AlmaLinux 8, providing more flexibility and control over the Git version installed on your system. Remember to weigh the benefits and risks of each approach before making a decision. When choosing how to install latest Git on AlmaLinux 8, consider your specific needs and risk tolerance. How To Install Latest Git on AlmaLinux 8 is an important task for developers, so choosing the right method is crucial.

Leave a Reply

Your email address will not be published. Required fields are marked *