How to Install Git on Debian 9
3 min read
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 .
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:
sudo apt update
Once the list is updated issue the following command to install Git:
sudo apt install git
Verify Git installation.
To verify the installation type the following command to print the Git version:
git 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 unzip
Once 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
At the time of writing this article, the latest stable Git version is
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:
wget command to download the archive file as
sudo wget https://github.com/git/git/archive/v2.18.0.tar.gz -O git.tar.gz
Once 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
Now, you can compile and install Git by typing these two commands:
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
Once the installation is completed verify it by typing the following command which will print the installed Git version:
git version 2.18.0
Later, if you want to upgrade to a newer version, you will need to repeat the installation process.
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 "firstname.lastname@example.org"
You can verify the changes with the following command:
git config --list
user.name=Your Name email@example.com
The configuration settings are stored in the
[user] name = Your Name email = firstname.lastname@example.org
If 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.
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.