How to install Git on Linux

Last updated on September 5, 2020 by Dan Nanni

Question: I am trying to clone a project from a public Git repository, but I am getting "git: command not found" error. How can I install git on [insert your Linux distro]?

Git is a popular open-source version control system (VCS) originally developed for Linux environment. Contrary to other VCS tools like CVS or SVN, Git's revision control is considered distributed in a sense that your local Git working directory can function as a fully-working repository with complete history and version-tracking capabilities. In this model, each collaborator commits to his or her local repository (as opposed to always committing to a central repository), and optionally push to a centralized repository if need be. This brings in scalability and redundancy to the revision control system, which is a must in any kind of large-scale collaboration.

Install Git with a Package Manager

Git is shipped with all major Linux distributions. Thus the easiest way to install Git is by using your Linux distro's package manager.

For Debian, Ubuntu, or Linux Mint:

$ sudo apt-get install git

For Fedora, CentOS or RHEL:

$ sudo yum install git

For Arch Linux:

$ sudo pacman -S git

For OpenSUSE:

$ sudo zypper install git

For Gentoo:

$ emerge --ask --verbose dev-vcs/git

Compile Git from the Source

If for whatever reason you want to built Git from the source, you can follow the instructions below.

Install Dependencies for Building Git

Before building Git, first install dependencies.

Debian, Ubuntu or Linux Mint:

$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x

Fedora, CentOS or RHEL:

$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc xmlto docbook2x

Compile Git from the Source

Download the latest release of Git from https://github.com/git/git/releases. Then build and install Git under /usr as follows.

Note that if you want to install it under a different directory (e.g., /opt), replace --prefix=/usr in configure command with something else.

$ cd git-x.x.x
$ make configure
$ ./configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean