Data report"State of code review 2024" is now liveRead the full report

How to install Git on Linux

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Git is a widely-used version control system that allows you to track changes in your codebase and collaborate with others. This guide will walk you through the steps to install Git on various Linux distributions.

To install Git on Ubuntu, follow these steps:

  1. Update the package index:

    Terminal
    sudo apt update
  2. Install Git:

    Terminal
    sudo apt install git
  3. Verify the installation:

    Terminal
    git --version

    You should see the installed Git version.

Debian is another widely-used Linux distribution. Here’s how you can install Git on Debian:

  1. Update the package index:

    Terminal
    sudo apt update
  2. Install Git:

    Terminal
    sudo apt install git
  3. Verify the installation:

    Terminal
    git --version

    You should see the installed Git version.

For Fedora users, the installation process is slightly different. Follow these steps:

  1. Update the package index:

    Terminal
    sudo dnf update
  2. Install Git:

    Terminal
    sudo dnf install git
  3. Verify the installation:

    Terminal
    git --version

    You should see the installed Git version.

CentOS users can install Git by following these steps:

  1. Install the required dependencies:

    Terminal
    sudo yum groupinstall "Development Tools"
    sudo yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel
  2. Download the latest Git source code:

    Terminal
    wget https://github.com/git/git/archive/v2.34.1.tar.gz -O git.tar.gz
  3. Extract the downloaded file:

    Terminal
    tar -zxf git.tar.gz
    cd git-2.34.1
  4. Compile and install Git:

    Terminal
    make prefix=/usr/local all
    sudo make prefix=/usr/local install
  5. Verify the installation:

    Terminal
    git --version

    You should see the installed Git version.

After installing Git, you should configure your Git environment. Follow these steps:

  1. Set your username:

    Terminal
    git config --global user.name "Your Name"
  2. Set your email:

    Terminal
    git config --global user.email "your.email@example.com"
  3. Verify your configuration:

    Terminal
    git config --list

    You should see your username and email configured.

If you need a specific version of Git or want to install the latest version, you can install Git directly from the source code. Follow these steps:

  1. Install the required dependencies:

    On Ubuntu/Debian:

    Terminal
    sudo apt update
    sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

    On Fedora:

    Terminal
    sudo dnf install dh-autoreconf curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel
    sudo dnf install asciidoc xmlto docbook2X
  2. Download the latest Git source code:

    Terminal
    wget https://github.com/git/git/archive/v2.34.1.tar.gz -O git.tar.gz
  3. Extract the downloaded file:

    Terminal
    tar -zxf git.tar.gz
    cd git-2.34.1
  4. Compile and install Git:

    Terminal
    make prefix=/usr/local all
    sudo make prefix=/usr/local install
  5. Verify the installation:

    Terminal
    git --version

    You should see the installed Git version.

Here are some common issues you might encounter during installation and their solutions:

  1. Permission denied errors:

    Ensure you are using sudo to install Git. For example:

    Terminal
    sudo apt install git
  2. Command not found:

    Ensure that Git is installed correctly and added to your system’s PATH. Verify the installation with:

    Terminal
    git --version

For further information see the official Git documentation.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2