How To Install Git on Centos 7 with Easy Steps – OrcaCore

Posted on

How To Install Git on Centos 7 with Easy Steps - OrcaCore

How To Install Git on Centos 7 with Easy Steps – OrcaCore

In this guide, we want to teach you How To Install Git on Centos 7. Git is a DevOps tool used for source code management. It is a free and open-source version control system used to handle small to very large projects efficiently. Git is used to track changes in the source code, enabling multiple developers to work together on non-linear development. Knowing how to install Git on Centos 7 is a fundamental skill for any developer working on a CentOS server.

Now proceed to the steps below on the Orcacore website to set up Git from the source on Centos 7.

Steps To Install and Configure Git on Centos 7

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Centos 7.

1. Install Git From source on Centos 7

Git packages are available in the default Centos repository. But in this guide, we will install Git in the latest version from the source. This method allows for more control over the specific version installed. Understanding how to install Git on Centos 7 from source gives you the flexibility to choose the exact version you need.

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

sudo yum update -y

Then, use the following command to install the required packages and dependencies:

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

Download Git From Source

Now you need to visit the Git Release page and find the master zip archive or the latest stable release from Git.

Next, use the wget command to Download Git From Source on Centos 7:

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

When your download is completed, unzip your file with the command below:

sudo unzip v2.39.0.zip

Switch to your Git directory:

cd git-2.39.0

Install Git Centos 7

At this point, use the following commands to install Git:

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

When you are done, verify your Git installation on Centos 7 by checking its version:

git --version
**Output**
git version 2.39.0

2. Configure Git on Centos 7

At this point, you must configure Git so that the generated commit messages you make will contain the correct information and support you as you build your software project.

You must provide your name and email address because Git embeds this information into each commit you make. To do this, you can use the following commands:

# 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 git config --list command:

git config --list
git config list

All the configuration done through the <mark>git command</mark> will save the information in a file called .gitconfig in the user’s home directory. So you can also verify the configuration by checking this file using cat ~/.gitconfig command as shown below:

cat ~/.gitconfig
Display gitconfig

Testing Git on Centos 7

Now that you have set up Git on Centos 7, you can try using it by performing Git clone operations from GitHub.

We can just clone a repository called wig by using **git clone** command as shown below. 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
Install Git on Centos 7

Also, you can check all the subcommands available with the git command using git help -a command as shown below:

git help -a

Conclusion

At this point, you have learned to Download Git From Source and Install it on Centos 7. Git is used on CentOS 7 for version control and managing code repositories. It helps track changes, collaborate with teams, and manage software development efficiently. It’s crucial to understand how to install Git on Centos 7 for effective collaboration and version control.

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

How To Install PHP 8.2 on Centos 7

How to Install and Use Docker on Centos 7

Install and Configure Varnish Cache For Apache on Centos 7

Alternative Solutions for Installing Git on CentOS 7

While installing Git from source offers the most control, it’s not always the most convenient or necessary approach. Here are two alternative methods for installing Git on CentOS 7:

1. Installing Git Using yum (From the CentOS Base Repository)

The simplest and most common method is to use the yum package manager to install Git from the CentOS base repository. This method is ideal when you don’t require a specific, very recent version of Git and prefer a straightforward installation process.

Explanation:

CentOS 7 comes with a default repository containing a stable version of Git. Using yum simplifies the installation as it automatically handles dependencies and package management. This is often sufficient for many development workflows.

Steps:

  1. Update the package index: This ensures you have the latest package information.

    sudo yum update -y
  2. Install Git: This command installs Git and its necessary dependencies from the CentOS base repository.

    sudo yum install git -y
  3. Verify the installation: Check the Git version to confirm the installation was successful.

    git --version

    The output will display the Git version available in the CentOS base repository.

Advantages:

  • Simple and quick installation.
  • Automatic dependency resolution.
  • Guaranteed compatibility with CentOS 7.

Disadvantages:

  • The Git version might not be the latest.
  • Less control over the specific version installed.

2. Installing Git Using IUS Community Repository

The IUS (Inline with Upstream Stable) Community Repository provides more recent versions of software packages, including Git, for CentOS. This method is suitable when you need a more up-to-date Git version than what’s available in the base repository, but you don’t want the complexity of building from source.

Explanation:

IUS aims to provide newer stable versions of packages while maintaining compatibility with CentOS. Installing from IUS is a good compromise between ease of use and access to more recent software.

Steps:

  1. Install the IUS repository: Download and install the IUS release package for CentOS 7.

    sudo yum install https://centos7.iuscommunity.org/ius-release.rpm -y
  2. Enable the IUS repository: Ensure the IUS repository is enabled. In most cases, this is automatic after installing the release package.

  3. Install Git from IUS: Use yum to install Git from the IUS repository.

    sudo yum install git2u -y

    Note: The package name might vary depending on the specific Git version available in IUS. Use yum search git to find available Git packages in the IUS repository. git2u represents git version 2.x, git3u represents git version 3.x etc.

  4. Verify the installation: Check the Git version to confirm the installation was successful.

    git --version

    The output will display the Git version installed from the IUS repository.

Advantages:

  • Provides more recent Git versions than the base repository.
  • Easier installation than building from source.
  • Good balance between stability and up-to-dateness.

Disadvantages:

  • Requires adding a third-party repository.
  • IUS might not always have the absolute latest Git version.

Choosing the right method depends on your specific needs and priorities. If simplicity and guaranteed compatibility are paramount, the base repository is the best choice. If you need a more recent version without the complexity of building from source, IUS is a good option. If you require a very specific or cutting-edge version of Git, installing from source is the most flexible approach.

Leave a Reply

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