How to Install Git on Debian 9

This tutorial will show you how to install and configure Git on Debian 9.
Git is the world’s most popular distributed version control system used by many open-source and commercial projects. 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 was tested on Debian 9 but it should also work with any previous Debian version .
Prerequisites
Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges .
Installing Git with Apt
The easiest and the recommended way to install Git is by using the apt
package management tool from the Debian’s default repositories. If you want to install the latest stable version of Git move on to the Installing Git from a Source section of this tutorial.
The following steps will show you how to install Git on your Debian system:
Update package index.
Before installing new packages you should always update the apt package index:
Terminalsudo apt updateInstall Git.
Once the list is updated issue the following command to install Git:
Terminalsudo apt install gitVerify Git installation.
To verify the installation type the following command to print the Git version:
Terminalgit --versionoutputgit version 2.11.0
As you can see from the output above, you have successfully installed Git version 2.11.0. You can now move on to the Configuring Git
section of this tutorial to complete your setup.
Installing Git from a Source
Another installation option is to compile Git from the source which will allow you to install the latest Git version and to customize the build options, but you won’t be able to maintain your Git installation through the apt package manager.
Before continuing with the next steps, first you need to install the packages necessary to build Git on your Debian system:
sudo apt update
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzipOnce the dependencies are installed open your browser, go to Git project’s mirror on GitHub
and copy the latest release link address that ends in .tar.gz
:

At the time of writing this article, the latest stable Git version is 2.18.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/Use the wget command
to download the archive file as git.tar.gz:
sudo wget https://github.com/git/git/archive/v2.18.0.tar.gz -O git.tar.gzOnce the download is complete, extract the file that you downloaded and switch to the git source directory by typing:
sudo tar -xf git.tar.gz
cd git-*Now, you can compile and install Git by typing these two commands:
sudo make prefix=/usr/local all
sudo make prefix=/usr/local installOnce the installation is completed verify it by typing the following command which will print the installed Git version:
git --versiongit version 2.18.0Later, if 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 recommended to set your Git commit email and username:
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"You can verify the changes with the following command:
git config --listuser.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 other changes to your Git configuration you can either use the git config command or edit the ~/.gitconfig file by hand. For more options, see our guide on configuring Git username and email
.
Conclusion
You have learned how to install Git on your Debian system. 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