How To Install Git from Source on Ubuntu 20.04
Tags: git, linux, tutorial, opensource
Published: 2020-07-01 20:53:39

---
title: How To Install Git from Source on Ubuntu 20.04
published: true
tags: git, linux, tutorial, opensource
description: A tutorial to walk you through installing Git from source on an Ubuntu 20.04 cloud server
canonical_url: https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-20-04
---

### Introduction

Version control systems like Git are essential to modern software development best practices. Versioning allows you to keep track of your software at the source level. You can track changes, revert to previous stages, and branch to create alternate versions of files and directories.

In this guide, we will go through how to install and configure Git on an Ubuntu 20.04 server via source. This provides you with a more flexibility, but takes longer than installing through your package manager (also note that Git will not be maintained through your package manager). Downloading the latest release will also provide you with access to the most recent functionality, and give you greater control over options and customizations.

## Prerequisites

This guide was tested on an Ubuntu 20.04 server with a non-root superuser account. 

If you need to set this up, you can follow the [Initial Server Setup Guide for Ubuntu 20.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04).

## Step 1 — Confirm Git Preinstallation

Verify the version of Git currently installed on the server:

```command
git --version
```

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

```
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

Before you begin, you need to install the software that Git depends on. This is all available in the default repositories, so we can update our local package index and then install the relevant packages.

```command
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

After you have installed the necessary dependencies, create a temporary directory and move into it. This is where we will download our Git tarball. 

```command
mkdir tmp
cd /tmp
```

From the [Git project website](https://git-scm.com/), we can navigate to the tarball list available at [https://mirrors.edge.kernel.org/pub/software/scm/git/](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`.

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

In the next step, we'll work with this tarball.

## Step 4 — Unpack Compressed File and Install the Package

Unpack the compressed tarball file:

```command
tar -zxf git.tar.gz
```

Next, move into the new Git directory:

```command
cd git-*
```

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

```command
make prefix=/usr/local all
sudo make prefix=/usr/local install
```

At this point, Git is installed and you can refresh your environment.

## Step 5 — Verify New Version of Git

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

```command
 exec bash
```

With this complete, you can be sure that your install was successful by checking the version.

```command
git --version
```

You should receive output similar to the following, with a more recent number than the preinstalled version of Git.

```
git version 2.26.2
```

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

## Step 6 — Set Up Git

After you are satisfied with your Git version, you should configure Git so that the generated commit messages you make will contain your correct information and support you as you build your software project.

Configuration can be achieved by using the `git config` command. Specifically, we need to provide our name and email address because Git embeds this information into each commit we do. We can go ahead and add this information by typing:

```command
git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"
```

We can display all of the configuration items that have been set by typing:

```command
git config --list
```

You'll get output to demonstrate that your name and email are set up.

```
user.name=Your Name
user.email=youremail@domain.com
...
```

The information you enter is stored in your Git configuration file, which you can optionally edit by hand with a text editor of your choice like this (we’ll use nano):

```command
nano ~/.gitconfig
```

The file will be similar to the following.

```
[user]
  name = Your Name
  email = youremail@domain.com
```

Press `CTRL` and `X`, then `Y` then `ENTER` to exit the text editor. 

There are many other options that you can set, but these are the two essential ones needed. If you skip this step, you’ll likely see warnings when you commit to Git. This makes more work for you because you will then have to revise the commits you have done with the corrected information.

## Conclusion

You should now have the most recent available version of Git installed and ready to use on your system. 

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

* [How To Use Git Effectively](https://www.digitalocean.com/community/articles/how-to-use-git-effectively)
* [How To Use Git Branches](https://www.digitalocean.com/community/articles/how-to-use-git-branches)
* [An Introduction to Open Source](https://www.digitalocean.com/community/tutorial_series/an-introduction-to-open-source)