In this guide we are going to see how we can install Git
in Linux, the famous version control system that most developers use. Git facilitates group work and code management, making the task of adding features to a team framework very easy. Installing Git
is very simple, and on most Linux distros you will be able to install Git with a couple of commands.
How to Install Git In Linux
The installation of Git in Linux very simple. Depending on your distribution you will have to use one package manager or another.
Debian / Ubuntu
To install git in linux, in this case Debian or Ubuntu we can use the apt
package manager to do so:
First, lets update the repositories:
sudo apt-get update
Then we can simply tell apt
to install git
sudo apt-get install git
Let’s check the current version of git to see if its installed on our system:
git --version
Output
git version 2.34.1
CentOS / Fedora / RHEL
You can install Git on systems running Fedora or RHEL/CentOS distributions using the yum
package manager.
yum install git
Let’s check git’s version to verify it has been installed on our system:
git --version
Output
git version 2.35.1
Installing a Specific version of Git in Linux (from Source)
Let’s say you are looking for a specific version of git to install on our system, or just simply the version of git
our package manager apt
or yum
installed an old version.
For this we need to compile Git
from the source to get the latest version or even the specific one we are after.
Debian / Ubuntu
First, lets update our packages and then install all the dependencies required:
sudo apt-get update
sudo apt install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev make gettext libz-dev libssl-dev libghc-zlib-dev
Then, navigate to the the Git’s release page on Github and copy the tar.gz
file URL
:
Then, we are going to download the file with the wget
command and extract the file with ta
r on the /usr/src
directory:
sudo wget -c https://github.com/git/git/archive/refs/tags/v2.36.1.tar.gz -O - | sudo tar -xz -C /usr/src
Once downloaded and extracted use the cd
command to navigate to the directory you just downloaded and extracted git to, in our case is the /usr/src/git-2.36.1
directory but in your case it might be different:
cd /usr/src/git-2.36.1/
Now, lets compile and install Git (it will take a few minutes)
make configure
sudo ./configure --prefix=/usr
sudo make
sudo make install
Once it has been completed, now let’s check the git version:
git --version
output
git version 2.36.1
CentOS / Fedora / RHEL
Similar to Debian-based distros we need to navigate to the Git’s release page on Github and copy the tar.gz URL.
Let first install the required packages:
sudo yum -y install wget perl-CPAN gettext-devel perl-devel openssl-devel zlib-devel curl-devel expat-devel asciidoc xmlto docbook2X autoconf
Then with the help of wget
and tar
we’ll download and extract the downloaded files:
sudo wget -c https://github.com/git/git/archive/refs/tags/v2.36.1.tar.gz -O - | sudo tar -xz -C /usr/src
Then use the cd
command to navigate to the extracted folder located at, in our case and yours will differ, /usr/src/git-2.36.1/
cd /usr/src/git-2.36.1/
Then lets compile and install (this will take some minutes):
make configure
sudo ./configure --prefix=/usr
sudo make
sudo make install
Let’s check git
‘s version:
git --version
Output
git version 2.36.1
With this we verified that git was installed successfully wit the version we downloaded and extracted.
Summary
This guide showed you got to install git
in Linux. It also showed you how to install a specific version of git
from source on your Debian/Ubuntu or RHEL-based system.