How to Install Git on Debian 9

By 

Updated on

4 min read

Install Git on Debian

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:

  1. Update package index.

    Before installing new packages you should always update the apt package index:

    Terminal
    sudo apt update
  2. Install Git.

    Once the list is updated issue the following command to install Git:

    Terminal
    sudo apt install git
  3. Verify Git installation.

    To verify the installation type the following command to print the Git version:

    Terminal
    git --version
    output
    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:

Terminal
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 .tar.gz :

Installing Git from Source

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:

Terminal
cd /usr/src/

Use the wget command to download the archive file as git.tar.gz:

Terminal
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:

Terminal
sudo tar -xf git.tar.gz
cd git-*

Now, you can compile and install Git by typing these two commands:

Terminal
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:

Terminal
git --version
output
git version 2.18.0

Later, 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:

Terminal
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"

You can verify the changes with the following command:

Terminal
git config --list
output
user.name=Your Name
user.email=youremail@yourdomain.com

The configuration settings are stored in the ~/.gitconfig file:

~/.gitconfigconf
[user]
    name = Your Name
    email = youremail@yourdomain.com

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. 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

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