Home  »  ArticlesGuidesHow ToSoftwareTechnologyTools   »   How To Install Git on CentOS 7 With Examples

How To Install Git on CentOS 7 With Examples

In the developer world, source control is important in that it allows the development teams to track and manage changes to code by keeping the history and helps resolve conflicts when merging contributions from multiple sources. Before we see how to install Git on CentOS 7 we need to know what Git is.

Git is a free and open-source distributed version control system. It is software designed for tracking changes in sets of files and directories. It aims to achieve speed, data integrity, and support for distributed, and non-linear workflows.

Git happens to be one of the most popular and active version control systems. Sites like GitHub, GitLab, and Bitbucket have made sharing and contributing to code with Git much easier and more widespread than ever.

Prerequisites

You will need a fully configured and working CentOS 7 server with a non-root user with sudo privileges. You should have basic knowledge of using the Linux terminal.

Step 1: Install Git on CentOS 7

Git is available in the CentOS software repositories so that is where we will install it from. This is the fastest method even though the downside of this method is that the Git version that is installed may be older than the newest version available. If you need the latest release, you can install Git from the source.

Let’s proceed. To install Git on CentOS 7 from the default software repositories we will be using yum, CentOS’s native package manager. We start by updating the package list and upgrading the Linux system:

$ sudo yum update && sudo yum upgrade

Now we install Git.

$ sudo yum install git

You can double-check the installation by checking the Git version using this:

$ git --version

Step 2: Setting Up Git

With Git installed, you need to configure it in ready for your first and subsequent uses. Here you will be configuring some information about yourself so that commit messages will be created with the correct information attached.

See also  Overview of Vulkan for GPU 3D Graphics and Compute

This is done by providing the name and email address that you would like to have embedded into your commits using the git config command:

$ git config --global user.name "Example User"
$ git config --global user.email "[email protected]"

Confirm your configurations.

$ git config --list
Output
user.name=Example User
[email protected]

Install the Latest Git From Source Code

Step 1: Download Git Source

You will need to download the latest version of Git. As of this posting, the latest version of Git is 2.35.0. You can check for the latest version at any point in time by navigating to this list https://mirrors.edge.kernel.org/pub/software/scm/git/. Once you have determined the version you can begin your installation.

Download and extract the tarball and go to the folder of the source code:

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

Note: Remember to use the correct tarball version in the commands above.

Step 2: Install the Dependencies

Run these commands to install the dependencies in case they are missing on your CentosOS 7 system.

$ sudo yum groupinstall 'Development Tools'
$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-CPAN perl-devel

Step 3: Compile and Install Git

Run the following commands to configure, compile and install Git.

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

Once complete, ensure that your install was successful by checking the version.

 git --version
Output
git version 2.35.0

Complete your setup as explained above using the git config command.

$ git config --global user.name "Example User"
$ git config --global user.email "[email protected]"

Confirm your configurations.

$ git config --list
Output
user.name=Example User
[email protected]

Conclusion

You should now have git installed and ready to use on your system. Whether you did install Git on CentOS 7 using the default software repositories or from the source.

See also  Qt World Summit is at Hand

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Share it!