Git is a popular distributed version control system used by many development teams around the world. There are multiple ways to download & configure git in Linux. In this article, we will look at how to install git in Ubuntu. You can either install it as a package on debian/ubuntu system, or from source. We will look at both these methods in detail.
How To Install git in Ubuntu
We will look at two ways to install git in Ubuntu – using package and from source.
Install Git from package
The easiest and recommended way to install git is using a package manager such as apt.
1. Install prerequisites
Open terminal and run the following command.
$ sudo apt update
Also read : How to Install Virtualenv in Ubuntu
2. Install git
Run the following command to install git
$ sudo apt install git
3. Check git version
Run the following command to check git version.
$ git --version
Also read : How to Change SSH Port in Ubuntu
Install git from source
In this method, we will download, unzip and install from git source code.
1. Install Dependencies
Open terminal and run the following.
sudo apt update$
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
Also read : How to Set up Automatic Updates in Ubuntu
2. Download git
Visit git mirror and find out the latest source code version.
Navigate to the folder where you want to download git source code.
$ cd /usr/src/
Run the following command to download git source code.
$ sudo wget https://github.com/git/git/archive/v2.43.0.tar.gz -O git.tar.gz
Also read : How to Password Protect Directory in NGINX
3. Extract .tar.gz file
Run the following command to extract .tar.gz file.
sudo tar -xf git.tar.gz$
4. Compile and Install git
Run the following command to compile and install git in Ubuntu.
sudo make prefix=/usr/local all$
sudo make prefix=/usr/local install
5. Verify Git version
After installation, run the following command to verify git version.
$ git --version 2.43.1
Run the following two commands to set up username and email for git user. Replace “Your Name” and email@example.com with your name and email respectively.
git config --global user.name "Your Name"$
git config --global user.email "firstname.lastname@example.org"