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

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

3 days ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 weeks ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

2 weeks ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

2 weeks ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

2 weeks ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

2 weeks ago