How To Install Git On Ubuntu 20.04 LTS

GIT
By bhagwatchouhan
How To Install Git On Ubuntu 20.04 LTS

Git is among the popular Version Control Systems and widely used by the developers to version control their project source code. We can use Git to track the code changes, merge code from collaborators, revert to previous versions. Git also provides options to manage branches to have an effective workflow used for development and production purposes. This tutorial provides all the steps required to install Git on Ubuntu 20.04 LTS. The steps should be the same on other versions of Ubuntu and Linux distributions.

 

Install Git From Ubuntu Repositories

This section provides the steps required to install Git from Ubuntu's default repositories using the APT Package Manager. Use the below-mentioned commands to install Git using apt.

# Refresh Packages List
sudo apt update
# Install Git sudo apt install git
# Output Reading package lists... Done Building dependency tree Reading state information... Done --- --- Preparing to unpack .../liberror-perl_0.17029-1_all.deb ... Unpacking liberror-perl (0.17029-1) ... Selecting previously unselected package git-man. Preparing to unpack .../git-man_1%3a2.25.1-1ubuntu3_all.deb ... Unpacking git-man (1:2.25.1-1ubuntu3) ... Selecting previously unselected package git. Preparing to unpack .../git_1%3a2.25.1-1ubuntu3_amd64.deb ... Unpacking git (1:2.25.1-1ubuntu3) ... Setting up liberror-perl (0.17029-1) ... Setting up git-man (1:2.25.1-1ubuntu3) ... Setting up git (1:2.25.1-1ubuntu3) ... Processing triggers for man-db (2.9.1-1) ...

We can also verify the Git using the git command as shown below.

# Verify Git
git --version
# Output git version 2.25.1

After confirming the Git using the version option, we can do the minimum configuration to start using Git by configuring the User and Email as shown below. You can provide your Name and the commonly used Email to be used globally.

# Configure Global Name
git config --global user.name "Name"
# Configure Global Email git config --global user.email "email@domain.com"

We can also manually edit the Name and Email by updating the Git config file as shown below.

# Edit the Git configuration using Nano Editor
sudo nano ~/.gitconfig
# Configure Name and Email by updating the file [user] name = Name email = email@domain.com

Press Ctrl + O to write the changes and Ctrl + X to exit Nano editor.  Also, verify the Git configurations using the command as shown below.

# View Git Configurations
git config --list
# Output user.name=Name user.email=email@domain.com

Now we can use Git to clone the existing project or initiate git for the new project and start committing the changes.

 

Uninstall Git

We can uninstall Git on Ubuntu 20.04 LTS using the apt command as shown below. Use the below-mentioned command to uninstall Git without removing the dependent packages.

# Uninstall Git 
sudo apt remove git

We can also remove the Git with all the dependant packages as shown below.

# Uninstall Git with dependent packages
sudo apt remove --auto-remove git
# Output Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: git git-man liberror-perl --- --- Removing git (1:2.25.1-1ubuntu3) ... Removing git-man (1:2.25.1-1ubuntu3) ... Removing liberror-perl (0.17029-1) ... ---- ---- Processing triggers for man-db (2.9.1-1) ...

The above-mentioned commands can be used to uninstall Git and it's dependencies without deleting the configurations and data files associated with Git installation. We can completely remove or uninstall Git using the purge command as shown below.

# Uninstall Git
sudo apt purge git
# OR Uninstall Git with dependent packages sudo apt purge --auto-remove git
# Output Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: git* git-man* liberror-perl* 0 upgraded, 0 newly installed, 3 to remove and 78 not upgraded. After this operation, 34.0 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 164319 files and directories currently installed.) Removing git (1:2.17.1-1ubuntu0.7) ... Removing git-man (1:2.17.1-1ubuntu0.7) ... Removing liberror-perl (0.17025-1) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... (Reading database ... 163413 files and directories currently installed.) Purging configuration files for git (1:2.17.1-1ubuntu0.7) ...

Also, verify the Git using the git command as shown below.

# Verify Git
git --version
# Output bash: /usr/bin/git: No such file or directory

 

Install Git From Source Code

In the previous sections, we have discussed about installing and uninstalling Git using the APT Package Manager on Ubuntu 20.04 from Ubuntu's default repositories. In several cases, it might be required to install the most recent version of Git. Since the default repositories might not have the most recent version of Git, we can always install the most recent version from the source code.

Step 1: The very first step is to install the essential build tools using the command as shown below.

sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip -y

Step 2a: Download Git on Ubuntu Desktop- Now open the browser, open the Git Project, select the Git version to be installed, and download it as shown in Fig 1, Fig 2, Fig 3, and Fig 4.

Install Git on Ubuntu 20.04 LTS - Home

Fig 1

Install Git on Ubuntu 20.04 LTS - Select Branch

Fig 2

Install Git on Ubuntu 20.04 LTS - Download

Fig 3

Install Git on Ubuntu 20.04 LTS - Save

Fig 4

Step 2b: Download Git on Ubuntu Server- Open the Git version history page and copy the link of the most recent release as shown in Fig 5.

Install Git on Ubuntu 20.04 LTS - Download Link

Fig 5

Right-click the zip or tarball and download it as shown below.

sudo wget https://github.com/git/git/archive/v2.26.2.zip
# OR
sudo wget https://github.com/git/git/archive/v2.26.2.tar.gz

Step 3: Now extract the downloaded zip and move it to the /usr/src directory as shown below.

# Unzip the Zip
sudo unzip git-2.26.2.zip
# Or Extract tarball sudo tar -xf v2.26.2.tar.gz
# Move to /usr/src sudo mv git-2.26.2 /usr/src/git-2.26.2 cd /usr/src/git-2.26.2

Step 4: Install Git from the source using the command as shown below.

sudo make prefix=/usr/local install

It will take some time to make and install Git from the source code.

Step 5: Verify the Git using the git command as shown below.

# Verify Git
git --version
# Output git version 2.26.2

Step 6: After confirming the Git using the version option, configure the User and Email as shown below. You can provide your Name and the commonly used Email to be used globally.

# Configure Global Name
git config --global user.name "Name"
# Configure Global Email git config --global user.email "email@domain.com"

We can also manually edit the Name and Email by updating the Git config file as shown below.

# Edit the Git configuration using Nano Editor
sudo nano ~/.gitconfig
# Configure Name and Email by updating the file [user] name = Name email = email@domain.com

Press Ctrl + O to write the changes and Ctrl + X to exit Nano editor. 

Step 7: Verify the Git configurations using the command as shown below.

# View Git Configurations
git config --list
# Output user.name=Name user.email=email@domain.com
This completes the installation of Git from the source code.

 

Summary

This tutorial provided the steps required to install and uninstall Git on Ubuntu 20.04 LTS using the APT package manager. It also provided the steps required to install the most recent version of Git using the source code.

Share this blog:

Profile picture for user bhagwatchouhan
bhagwatchouhan