git

How to Install git on CentOS 7/8 ?

Git is the most widely used open source version control system that tracks all files in a project and every file change is detected and versioned. You would therefore a modification history which allows you to consult it and even go back in case of error.

We will see in this article the two methods to install git on CentOS.

Installation with yum or dnf :

Use the command below to install our package with yum or dnf :

[root@server ~]# dnf install git
Loaded plugins: fastestmirror
Determining fastest mirrors
base: mirror.marwan.ma
extras: mirror.marwan.ma
updates: mirror.marwan.ma
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 243 kB 00:00:01
(2/2): updates/7/x86_64/primary_db | 10 MB 00:00:27
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-23.el7_8 will be installed
--> Processing Dependency: perl-Git = 1.8.3.1-23.el7_8 for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl >= 5.008 for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: rsync for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(warnings) for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(vars) for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(strict) for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(lib) for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(Term::ReadKey) for package: git-1.8.3.1-23.el7_8.x86_64

Once installed, you can check the version with the command below :

[root@server ~]# git --version
git version 1.8.3.1

Install git from source :

If you want to download the latest version then you need to compile git from source, It takes longer and will not be updated and maintained through the yum package manager, but it will allow you to download a newer version than the one available through CentOS repositories.

First we will need to install some dependencies available from the CentOS repository :

[root@server ~]# yum groupinstall "Development Tools"
[root@server ~]# yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel

After installing the necessary dependencies, you can find the version of Git you want to install by visiting this page.

git

Copy the link of the package you want to install :

git

We will use the wget command to download this package with the link copied :

[root@server ~]# wget https://github.com/git/git/archive/refs/tags/v2.33.0.tar.gz
--2021-09-06 12:03:59-- https://github.com/git/git/archive/refs/tags/v2.33.0.tar.gz
Resolving github.com (github.com)… 140.82.121.3
Connecting to github.com (github.com)|140.82.121.3|:443… connected.
HTTP request sent, awaiting response… 302 Found
Location: https://codeload.github.com/git/git/tar.gz/refs/tags/v2.33.0 [following]
--2021-09-06 12:04:00-- https://codeload.github.com/git/git/tar.gz/refs/tags/v2.33.0
Resolving codeload.github.com (codeload.github.com)… 140.82.121.9
Connecting to codeload.github.com (codeload.github.com)|140.82.121.9|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v2.33.0.tar.gz’
[ <=> ] 10,336,788 1.07MB/s in 12s
2021-09-06 12:04:12 (845 KB/s) - ‘v2.33.0.tar.gz’ saved [10336788]

if you don’t wget installed, you can install it with the command below :

[root@server ~]# yum install wget

We must now extract the tar.gz file :

[root@server ~]# tar xzf v2.33.0.tar.gz
[root@server ~]# ll
total 566140
drwxrwxr-x. 26 root root 16384 Aug 16 15:15 git-2.33.0

Go to the extracted folder and type the commands below :

[root@server ~]# make configure
[root@server ~]#./configure --prefix=/usr/local
[root@server ~]# make install

Git is now installed, type the command below to check the version :

[root@server git-2.33.0]# git --version
git version 1.8.3.1

Now that our git is installed, we need to provide some information about us (name, email) so the validation messages are generated with the information provided :

[root@server]# git config --global user.nom "Votre Nom"
[root@server]# git config --global user.email "vous@example.com"

To make sure that the information is correctly provided, type the command below :

[root@server]# git config --list
user.nom=Votre Nom
user.email=vous@example.com

Now git is properly installed and ready to use on your system.