How to install git on Ubuntu 18.04 Bionic Beaver Linux

Objective

The objective is to install the distributed version control system git on Ubuntu 18.04 Linux. First, we will be installing git on Ubuntu from a standard Ubuntu repository and later we will perform git installation from the source code.

Operating System and Software Versions

  • Operating System: – Ubuntu 18.04 Bionic Beaver

Requirements

Privileged access to your Ubuntu System as root or via the sudo command is required.

Conventions

  • # – requires given linux commands to be executed with root privileges either directly as a root user or by use of the sudo command
  • $ – requires given linux commands to be executed as a regular non-privileged user

Other Versions of this Tutorial

Ubuntu 20.04 (Focal Fossa)

Instructions

Install Git on Ubuntu from repository

First we will be installing git on Ubuntu from its standard repository. To do so simply execute the command:

ubuntu:~$ sudo apt -y install git

Once ready you can check for a correct git installation by retrieving git’s version:

$ git --version
git version 2.15.1

You have now installed git on your Ubuntu system.

Install Git on Ubuntu from Source Code

Installation of git from a standard Ubuntu repository does not yield the latest git version. In some rare cases you may wish to install the latest git version. To do so we need to install Git from the source code.

Let’s start by installation of all prerequisites. Enter the command:

ubuntu:~$ sudo apt -y install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

Next, use your browser and head over to the official git repository:

ubuntu install git - select version

Select master branch. Next, click on Tags and select your desired Git version you wish to install. Due to the possible unstable nature, it is a good idea to avoid release candidate (rc) versions if possible.


install git on ubuntu - download

From here click on Clone or Download button. Next, right click on Download ZIP and select Copy link address.




Back to your terminal, use wget command to download Git zip package using the previously retrieved git link download address. Example:

ubuntu:~$ wget https://github.com/git/git/archive/v2.16.2.zip

Unzip the download git package. Your git version number may be different:

ubuntu:~$ unzip v2.16.2.zip

At this stage we are ready to compile and install git. The following sets of commands will compile the previously downloaded git source code and install git binaries on your Ubuntu 18.04 linux system. Change the version number where appropriate:

ubuntu:~$ cd  git-2.16.2
ubuntu:~$ make prefix=/usr/local all
ubuntu:~$ sudo make prefix=/usr/local install

If all went well you should now have git installed on your Ubuntu 18.04 system. To confirmg run:

ubuntu:~$ git --version
git version 2.16.2

Post-Install git Configuration

You can now use git to clone any repository. However if you wish to make git commits you first need to set your personal information which will be submitted to main branch with each your commit. Enter the following linux commands to set your Name and email address:

ubuntu:~$ git config --global user.name "Your Name Here"
ubuntu:~$ git config --global user.email "youremail@address.here"

You can always change this settings by editing the main ~/.gitconfig git configuration file located withhin your home directory:

[user]
        name = Your Name Here
        email = youremail@address.here