How to Install Git on CentOS 8

Published on

3 min read

Install Git on CentOS 8

Git is a distributed version control system that’s being used by most software teams today. It allows you to keep track of your code changes, revert to previous stages, create branches , and to collaborate with your fellow developers.

Git is originally developed by Linus Torvalds , the creator of the Linux kernel.

This tutorial explains how to install Git on CentOS 8.

The easiest and the recommended way to install Git is to install it using the yum package management tool.

If you want to install the latest stable version of Git from source, scroll down to the Installing Git from the Source section of this tutorial.

Installing Git with Yum

The Git package is included in the CentOS’s default repositories.

Run the following command as root or user with sudo privileges to install Git on your CentOS system:

sudo yum install git

Verify the installation by typing the command below, which will print the Git version:

git --version

At the time of writing this article, the current version of Git available in the CentOS 8 repositories is 2.18.1.

git version 2.18.1

That’s it! You have installed Git, and you’re ready to use it.

Installing Git from the Source

Compiling Git from the source allows you to install the latest Git version and to customize the build options. However, you will not be able to maintain your Git installation through the yum package manager.

Start by installing the dependencies necessary to build Git on CentOS:

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

Once the installation is complete, open your browser, visit the Git project’s mirror on GitHub and copy the latest release link URL that ends in .tar.gz:

Installing Git from Source

Currently, the most recent stable Git version is 2.23.0, but it may be different for you.

We are going to download Git source in the /usr/src directory, which is the common location to place source files. Navigate to the directory :

cd /usr/src/

Download the tar.gz file as git.tar.gz using the link you copied earlier:

sudo wget https://github.com/git/git/archive/v2.23.0.tar.gz -O git.tar.gz

Next, extract the tarball and change to the git source directory by typing:

sudo tar -xf git.tar.gzcd git-*

Run the following two commands to compile and install Git on your CentOS system:

sudo make prefix=/usr/local allsudo make prefix=/usr/local install

Type git --version to verify the installation:

git --version
git version 2.23.0

Later, when you want to update to a newer version, download the archive and repeat the build process.

Configuring Git

Now that you have Git installed on your CentOS machine, it is a good idea to set up your personal information. The following commands will set your commit name and email address:

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

To confirm that you have set your information correctly in Git, type:

git config --list
user.name=Your Name
user.email=youremail@yourdomain.com

The configuration settings are stored in the ~/.gitconfig file:

~/.gitconfig
[user]
    name = Your Name
    email = youremail@yourdomain.com

If you want to make additional changes to the global Git configuration, use either the git config command or edit the ~/.gitconfig file by hand.

Conclusion

Installing Git on CentOS 8 is a matter of running a single yum command. If you want to use the latest Git version, you’ll need to build it from the source.

If you are new to Git check the Pro Git book , which is an excellent resource for learning about how to use Git.

Leave a comment below if you hit a problem or have feedback.