Git is the most popular distributed version control system. It used to track changes in source code during software development. It allows to collaborate with programmers, revert to previous changes and create branches. In this tutorial, you will learn how to install Git on Debian system.
You must have logged in with non-root user account with sudo privileges.
Install Git on Debian with Apt
Git is available at Debian default apt repository so we will install from there. It’s always recommended to install packages from Debian default repository.
So first of all we need to update apt package manager index using below command:
sudo apt update
Once the list is updated execute the below command to install Git:
sudo apt install git
You can verify the installation by typing:
It will show output like below:
git version 2.11.0
That’s all. You have successfully installed Git version on you Debian system.
Installing Git from a Source
Another installation method is to compile the software from source. It will allow you to download the latest release and to do customization. But you can’t manage Git package from
apt package manager.
Before you start, you need to install necessary software which Git required. These all are available from default Debian repository. Execute below commands:
sudo apt update
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
After that, you can go ahead and get the version of Git you want by visiting the Git project’s mirror on GitHub and copy the latest release link address that ends in .zip
Now we will download Git source to /tmp directory on your Debian system. Move to /tmp directory by typing:
Use the wget command to download the archive file as git.zip:
sudo wget https://github.com/git/git/archive/v2.21.0.zip -O git.zip
Once download is finished, unzip the downloaded file and move to the git source directory by typing:
Now, you can compile and install Git by typing these two commands:
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
Again, you can verify installation by typing:
It should show installed version of Git as given below:
git version 2.21.0
Later, if you have need to upgrade to a newer version, you can repeat the installation process.
Setting Up Git
Now your Git is installed and you need to configure it by setting up email address and username:
git config --global user.name "Admin"
git config --global user.email "email@example.com"
You can see entered details by typing:
git config --list
These settings are stored at
~/.gitconfig file and you can see content as below:
name = Admin
email = firstname.lastname@example.org
You can make other git configuration changes by using
git config command or you can edit the
~/.gitconfig file manually.
Finally, you have learned how to install Git on your Debian server and how to Setting up Git.
If you face any problem at installation time, leave a comment below.