How To Install Git on CentOS 8 – DigitalOcean

Version

control systems are an indispensable part of modern software development. Version control allows you to track your software at the source level. You can track changes, revert to previous stages, and branch to create alternate versions of files and directories.

One of the most popular version control systems currently available is Git. Many project files are maintained in a Git repository, and sites like GitHub, GitLab, and Bitbucket help facilitate sharing and collaboration of software development projects.

In this guide, we will see how to install and configure Git on a CentOS 8 server. We’ll cover how to install the software in two different ways: through the built-in package manager and through the source. Each of these approaches has its own benefits depending on your specific needs.

Prerequisites

You will need a CentOS 8 server with

a non-root superuser account

.

To set this up, you can follow our Initial Server Setup Guide for CentOS 8

.

With your server and user set up, you’re ready to go

. Installing Git with default packages Our first option for installing Git is

through the default CentOS packages. This option is

best for those who want to get up and running quickly with Git, those who prefer a widely used stable version, or those who aren’t looking for the newest options available.

If you are looking for the latest version, you should skip to the section about installing from source.

We will use the open source package manager tool DNF, which stands for Dandified YUM, the next generation version of the Yellowdog Updater, Modified (i.e. yum). DNF is a package manager that is now the default package manager for Red Hat-based Linux systems such as CentOS. It will allow you to install, update, and remove software packages on your server.

First, use the DNF package management tools to update the local package index.

sudo dnf update -y The -y

indicator is used to alert the system that we are aware that we are making changes, preventing the terminal from asking us to confirm.

With the update complete,

you can install Git:

  1. sudo dnf install

git -y

You can confirm that you have successfully installed Git by running the following command:

  1. git –

version Outputgit version 2.18.2 with Git

successfully installed, you can now move to the Git Settings section of this tutorial to complete your setup

.

Installing

Git from source

A more flexible method of installing Git is to compile the software from source. This takes longer and won’t be maintained through your package manager, but it will allow you to download the latest version and give you some control over the options it includes if you want to customize.

Before you begin, you must install the software that Git depends on. All of this is available in the default repositories, so we can update our local package index and then install the packages.

sudo dnf update -y

  1. sudo dnf
  2. install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel gcc autoconf –

and

After you have installed the necessary dependencies, create a temporary directory and move to it. This is where we will download our Git tarball.

  1. mkdir tmp
  2. cd /tmp

From the Git project website, we can navigate to the Red Hat Linux distribution tarball list available on https://mirrors.edge.kernel.org/pub/software/scm/git/ and download the version you want. At the time of writing, the most recent version is 2.26.0, so we will download it for demonstration purposes. We will use curl and generate the file that we downloaded on git.tar.gz.

curl -o git.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.26.0.tar.gz

Unzip the compressed tarball file

: tar –

  1. zxf

git.tar.gz

Next, go to the new Git directory

:

  1. cd git-*

Now, you can create the package and install it by typing these two commands:

make prefix=/usr/local

    all

  1. sudo make prefix=/usr/local install

With this complete, you can be sure that your installation was successful by checking the version.

  1. git -version

Outputgit version 2.26.0 With Git installed successfully, you can now complete your setup.

Configuring

Git Now that you

have Git installed, you must configure it so that the generated commit messages contain your correct information

.

This can be achieved using the git config command. Specifically, we need to provide our name and email address because Git incorporates this information into every engagement we make. We can go ahead and add this information by

typing: git config -global user.name “Your Name” git config -global user.email “youremail@domain.com”

We can display all the configuration items that have been set by typing:

  1. git config -list

Outputuser.name=Your

  1. Name

user.email=youremail@domain.com …

The information you enter is stored in your Git configuration file, which you can optionally edit by hand with a

text editor like this:

  1. vi ~/.gitconfig

[user] name = Your Name email = youremail@domain.com

Press ESC and then :q to exit the text editor

.

There are many other options you can configure, but these are the two necessary essentials. If you skip this step, you’ll likely see warnings when you commit to Git. This does more work for you because you will then have to review the confirmations you have made with the corrected information.

Conclusion

You should now have Git installed and ready to use on your system.

For more information about using Git, see these articles and series:

How to use Git

  • effectively How to use
  • Git branches
  • An introduction to open source