GitInstall Git on Linux

Install Git on Linux

Linux distributions almost all ship Git in their default package repositories, so installation is a single command. The exact command depends on which package manager your distro uses.

Check if Git is already installed

Bash
git --version

Many distros (especially server installs) include Git out of the box because tools like apt, dnf, and various install scripts rely on it.

Debian / Ubuntu / Mint / Pop!_OS / Kali

apt

Bash
sudo apt update
sudo apt install git

Ubuntu LTS releases sometimes lag a few Git versions behind. For the latest, add the official PPA:

Latest Git on Ubuntu via PPA

Bash
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
Fedora / RHEL 8+ / CentOS Stream / Rocky / Alma

dnf

Bash
sudo dnf install git
RHEL 7 / CentOS 7 (older)

yum

Bash
sudo yum install git
Arch / Manjaro / EndeavourOS

pacman

Bash
sudo pacman -S git
openSUSE

zypper

Bash
sudo zypper install git
Alpine

apk

Bash
apk add git
Gentoo

emerge

Bash
sudo emerge --ask --verbose dev-vcs/git
Verify the installation

Bash
git --version
# Example: git version 2.43.0
First-time configuration

Tell Git who you are

Bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main

# Sensible defaults
git config --global core.editor "vim"            # or nano, code --wait, etc.
git config --global pull.rebase false
git config --global core.autocrlf input          # LF in repo, native on disk
Why no autocrlf on Linux?
Linux uses LF (Unix) line endings natively, so no conversion is needed. `core.autocrlf input` makes Git convert any accidental CRLF to LF on commit while leaving the working tree alone.
Building from source (latest version)

If you need an even newer Git than what your distro provides, you can compile from source. Most people will never need this.

Build Git from source on Debian/Ubuntu

Bash
# Install build dependencies
sudo apt install -y dh-autoreconf libcurl4-gnutls-dev libexpat1-dev \
    gettext libz-dev libssl-dev install-info \
    asciidoc xmlto docbook2x

# Download and build
wget https://github.com/git/git/archive/v2.43.0.tar.gz
tar -zxf v2.43.0.tar.gz
cd git-2.43.0
make prefix=/usr/local all
sudo make prefix=/usr/local install
Updating Git
  • Debian/Ubuntu: sudo apt update && sudo apt upgrade git

  • Fedora: sudo dnf upgrade git

  • Arch: sudo pacman -Syu git

  • openSUSE: sudo zypper update git

  • Alpine: apk upgrade git

Common problems
  • E: Unable to locate package git on Ubuntu — your apt sources are stale. Run sudo apt update first.

  • Permission denied — never run git itself with sudo. Permission errors usually mean the working directory belongs to root, not you. Fix with sudo chown -R you:you my-project.

  • TLS / certificate errors behind a corporate proxy — install your company’s CA bundle and point Git at it: git config --global http.sslCAInfo /path/to/ca-bundle.crt.

  • Old Git on a stable distro — use the official PPA (Ubuntu) or build from source. Most features work fine on slightly older Git, so do this only if you need a specific feature.

Bash completion and prompt

Most distros bundle Bash completion for Git. To get a prompt that shows the current branch, add this to your ~/.bashrc:

Bash prompt with branch name

Bash
source /usr/share/git/completion/git-prompt.sh 2>/dev/null \
  || source /usr/lib/git-core/git-sh-prompt 2>/dev/null

PS1='\u@\h:\w\[\033[36m\]$(__git_ps1 " (%s)")\[\033[0m\]\$ '
Tip
On servers where you only need to read remotes, no extra setup is required after install. For day-to-day development, take a few minutes to install completion and a branch-aware prompt — it saves a lot of `git status` calls.