How to install Git on Ubuntu

Git is a version control system used to track file changes in source code. It allows developers to work on the same project simultaneously. Let’s look at how to install and configure Git on an Ubuntu server.

Installing Git

Ubuntu 20.04 comes with Git preinstalled most of the time. To check if it’s already installed or not, execute the following command in the Ubuntu terminal:

git --version

The following message would mean that Git is already installed:

The Git version on your machine might be different than the one shown above.

However, if we get a command not found error, we’d need to install Git manually. So, first, execute the following command to update the package lists for available software packages:

apt-get update

Next, run the following command to install Git:

apt-get install git

This command will install a version of Git that’s considered stable at the time of installation.

Once the setup is finished, execute the following command again to make sure that the installation was successful:

git --version

Configuring Git

We also need to configure Git to be able to use it properly. Every Git commit needs our name and email address, which we can configure using the git config command as follows:

git config --global user.name "username"
git config --global user.email "email"

Note: Replace username and email with your actual username and email address, which are usually the same as those on your GitHub account.

The following terminal runs Ubuntu 20.04. Click the “Click to Connect...” text to connect the terminal and try executing the commands given above to install and configure Git.

Terminal 1
Terminal
Loading...

Once done, Git will be set up and we can begin working with it. Happy Git-ing!

Copyright ©2024 Educative, Inc. All rights reserved