How To

Install Git on Ubuntu 18.04: Setup and Configuration Guide

Git is the de-facto standard for version control in software development. It tracks every change to your code, lets you revert to earlier states, create branches for new features, and collaborate with your team without overwriting each other’s work. Teams use Git to work on the same codebase in parallel and keep a complete history of every change ever made to a project.

Git was originally created by Linus Torvalds — the same person who wrote the first version of the Linux kernel.

This guide shows you how to install Git on Ubuntu 18.04 using the apt package manager or by compiling from source, and how to configure your user identity before making your first commit. The same steps apply to Ubuntu 16.04 and other Ubuntu-based distributions.

<strong>Prerequisite:</strong>&nbsp;You need sudo access.

Install Git on Ubuntu Using apt

The quickest and recommended way to install Git is from Ubuntu’s default repositories. The version available may not be the absolute latest, but it is stable, well-tested, and maintained automatically by apt.

Update the package index:

bashsudo apt update

Install Git:

bashsudo apt install git

Verify the installation:

bashgit --version

Output:

git version 2.17.1

Git 2.17.1 is the version included in the Ubuntu 18.04 repositories. If this version meets your needs, skip ahead to the Configuration section below.

Install Git from Source

If you need a newer Git release than what Ubuntu’s repositories offer, you can compile it directly from source. The trade-off is that apt cannot manage this installation, you have to repeat the build process each time a new version is released.

Install the required build dependencies:

bashsudo apt updatesudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

Visit the Git releases page on GitHub to find the latest stable version. At the time of writing, that is 2.23.0. Update the version number in the commands below if a newer release is available.

Download the source archive:

bashsudo wget https://github.com/git/git/archive/v2.23.0.tar.gz -O git.tar.gz

Extract the archive and move into the source directory:

bashsudo tar -xf git.tar.gzcd git-*

Compile and install Git:

bashsudo make prefix=/usr/local allsudo make prefix=/usr/local install

Confirm the installed version:

bashgit --version

Output:

git version 2.23.0

Configure Git for First Use

Before you start making commits, Git needs to know who you are. It attaches your name and email address to every commit you create. Set your global identity with these two commands:

bashgit config --global user.name "Your Name"git config --global user.email "youremail@yourdomain.com"

The --global flag applies these settings to all repositories on your system. If you need different credentials for a specific project, run the same commands from inside that project’s directory and leave out --global.

Verify your configuration is saved:

bashgit config --list

Output:

user.name=Your Nameuser.email=youremail@yourdomain.com

Git stores these settings in the ~/.gitconfig file in your home directory. You can open and edit it directly if you need to make any further adjustments.

Git is now installed and configured on your Ubuntu 18.04 system. You are ready to initialize repositories, clone projects, create branches, and start collaborating with your team. Leave a comment below if you run into any issues during the setup.

Cyber Defence

Recent Posts

Install Webmin on Ubuntu 18.04: Web Control Panel Setup Guide

Webmin is an open-source, browser-based control panel for Linux server administration. Instead of managing your server…

15 minutes ago

Install Go on Ubuntu 18.04: Tarball Setup and Hello World Guide

Go (also called Golang) is a modern, statically typed programming language created at Google. It is…

18 minutes ago

Install Google Chrome on Ubuntu 18.04: Complete Setup Guide

Google Chrome is the most widely used web browser in the world. It is fast, secure,…

20 minutes ago

Install Eclipse IDE on Ubuntu 18.04: Quick Snap Setup Guide

Eclipse is one of the most widely used integrated development environments in the world. It is…

23 minutes ago

Install Python 3.7 on Ubuntu 18.04: apt and Source Build Methods

Python 3.7 was a significant release for the language. It introduced data classes, a decorator that automatically…

1 day ago

Install Odoo 13 on Ubuntu 18.04: Python Venv and Nginx Guide

Odoo is a popular open-source suite of business applications. A single platform covers CRM, e-commerce, accounting,…

1 day ago