How To Install Git from Source on Ubuntu 20.04 [Quickstart]

Introduction

Version control systems help you collaborate on software development projects. Git is one of the most popular version control systems currently available.

This tutorial will walk you through installing and configuring Git from source on an Ubuntu 20.04 server. For a more detailed version of this tutorial, with more thorough explanations of each step, please refer to How To Install Git on Ubuntu 20.04.

Step 1 — Confirm Git Preinstallation

Verify whether you have a version of Git currently installed on the server:

  • git –version

If Git is installed, you’ll receive output similar to the following:

Output
git version 2.25.1

Whether or not you have Git installed already, it is worth checking to make sure that you install a more recent version during this process.

Step 2 — Update and Install Dependencies

You’ll next need to install the software that Git depends on. This is all available in the default Ubuntu repositories, so we can update our local package index and then install the relevant packages.

  • sudo apt update
  • sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc

Press y to confirm if prompted. Necessary dependencies should now be installed.

Step 3 — Install Tarball

Create a temporary directory to download our Git tarball and move into it.

  • mkdir tmp
  • cd /tmp

From the Git project website, we can navigate to the tarball list available at https://mirrors.edge.kernel.org/pub/software/scm/git/ and download the version you would like. At the time of writing, the most recent version is 2.26.2, so we will download that for demonstration purposes. We’ll use curl and output the file we download to git.tar.gz.

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

Step 4 — Unpack Compressed File and Install the Package

Unpack the compressed tarball file:

  • tar -zxf git.tar.gz

Next, move into the new Git directory:

  • cd git-*

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

  • make prefix=/usr/local all
  • sudo make prefix=/usr/local install

Now, replace the shell process so that the version of Git we just installed will be used:

  • exec bash

Step 5 — Verify New Version of Git

You can be sure that your install was successful by checking the version.

  • git –version
Output
git version 2.26.2

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

Step 6 — Set Up Git

Now that you have Git installed and to prevent warnings, you should configure it with your information.

  • git config –global user.name “Your Name
  • git config –global user.email “[email protected]

If you need to edit this file, you can use a text editor such as nano:

  • nano ~/.gitconfig
~/.gitconfig contents
[user]
  name = Your Name
  email = [email protected]

To learn more about how to use Git, check out these articles and series:

How To Install Git on Ubuntu 18.04 LTS

Install Git on Ubuntu 18

Git is a free and open source distributed version control system . Git 2.16.2 comes with the large number of updates verses previous release 2.15. It is designed to handle a small to very large projects with speed and efficiency.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Git on a Ubuntu 18.04 (Bionic Beaver) server.

Install Git on Ubuntu 18.04 LTS Bionic Beaver

Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.

sudo apt-get update
sudo apt-get upgrade

Step 2. Installing Git on Ubuntu 18.04 LTS.

Method 1. Install Git on Ubuntu from repository.


sudo apt install git -y

To check current version installed of Git use following command:

[[email protected] ~]# git --version
git version 2.15.1

Method 2. Install Git on Ubuntu from Source Code

First, install all prerequisites:

sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
sudo wget https://github.com/git/git/archive/v2.16.2.zip
sudo unzip v2.16.2.zip

Next, compile the previously downloaded git source code and install git binaries:

cd git-2.16.2
make prefix=/usr/local all
sudo make prefix=/usr/local install

Confirm Git the installation . Run the following command to verify which version of git is installed:

[[email protected] ~]# git --version
git version 2.16.2

Congratulation’s! You have successfully installed Git. Thanks for using this tutorial for installing Git in Ubuntu 18.04 LTS (Bionic Beaver) systems. For additional help or useful information, we recommend you to check the official Git web site.

How To Install Git on Ubuntu 16.04

Install Git on Ubuntu 16

Git is a free and open source distributed version control system . Git 2.9.3 comes with the large number of updates verses previous release 2.8. It is designed to handle a small to very large projects with speed and efficiency.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Git on a Ubuntu 16.04 (Xenial Xerus) server.

Install Git on Ubuntu 16.04

Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.

sudo apt-get update
sudo apt-get upgrade

Step 2. Installing Git.

Ubuntu 16.04 comes with Git 2.7.x, which is a little old now. As versions 2.9 are not part of the Ubuntu repositories, you need to add the git-core personal package archive. Run the following commands in Terminal to install Git 2.9.3 on Ubuntu, via PPA:

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git

To check current version installed of Git use following command:

[root@wpcademy ~]# git --version
git version 2.8.1

Congratulation’s! You have successfully installed Git. Thanks for using this tutorial for installing Git in Ubuntu 16.04 (Xenial Xerus) systems. For additional help or useful information, we recommend you to check the official Git web site.