How to Install Git on Ubuntu 18.04

Photo by varianto25
Git is a de-facto standard for distributed version control systems and is used by the majority of developers nowadays. It allows you to keep track of your code changes, revert to previous stages, create branches, and to collaborate with your fellow developers.
Git is originally developed by Linus Torvalds , the creator of the Linux kernel.
This tutorial will guide you through the steps required to install Git on Ubuntu 18.04. The same instructions apply for Ubuntu 16.04 and any other Ubuntu-based distribution, including Kubuntu, Linux Mint and Elementary OS.
Prerequisites
Before continuing with this tutorial, make sure you are logged in as root or a user with sudo privileges .
Installing Git with Apt
The easiest and the recommended way to install Git is to install it using the apt
package management tool from Ubuntu’s default repositories. If you want to install the latest stable version of Git from source, move on to the Installing Git from the Source
section of this tutorial.
Follow these steps to install Git on your Ubuntu system:
Start by updating the package index:
Terminalsudo apt updateRun the following command to install Git:
Terminalsudo apt install gitVerify the installation by typing the following command which will print the Git version:
Terminalgit --versionAt the time of writing this article, the current version of Git available in the Ubuntu 18.04 repositories is
2.17.1.outputgit version 2.17.1
That’s it, you have successfully installed Git on your Ubuntu and you can start using it.
Installing Git from the Source
Another option is to compile Git from the source, which will allow you to install the latest Git version and to customize the build options. However, you will not be able to maintain your Git installation through the apt package manager.
First, install the dependencies necessary to build Git on your Ubuntu system:
sudo apt update
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzipOnce the installation is complete open your browser, visit the Git project’s mirror on GitHub
and copy the latest release link URL that ends in .tar.gz:

At the time of writing this article, the latest stable Git version is 2.23.0.
We are going to download Git source in the /usr/src directory which is the common location to place source files, change to the directory
with:
cd /usr/src/Download the file as git.tar.gz using the link you copied earlier:
sudo wget https://github.com/git/git/archive/v2.23.0.tar.gz -O git.tar.gzNext, extract the tar.gz file and change to the Git source directory by typing:
sudo tar -xf git.tar.gz
cd git-*Run the following two commands to compile and install Git on your Ubuntu system:
sudo make prefix=/usr/local all
sudo make prefix=/usr/local installTo verify the installation type the following command which will print the installed Git version:
git --versiongit version 2.23.0If you want to upgrade to a newer version, you will need to repeat the installation process.
Configuring Git
Now that you have git installed, it is a good idea to set up your personal information that will be used when you commit your code.
The following commands will set your git commit username and email address:
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"To verify the configuration changes, type:
git config --listThe output should look something like this:
user.name=Your Name
user.email=youremail@yourdomain.comThe configuration settings are stored in the ~/.gitconfig file:
[user]
name = Your Name
email = youremail@yourdomain.comIf you want to make further changes to your Git configuration, you can either use the git config command or edit the ~/.gitconfig file by hand.
Conclusion
Installing Git on Ubuntu is a matter of running a single apt command. If you want to use the latest Git release, you’ll need to compile it from the source.
You should now check the Pro Git book and learn more about how to use Git.
If you hit a problem or have feedback, leave a comment below.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page