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
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
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
sudo add-apt-repository ppa:git-core/ppa sudo apt update sudo apt install git
Fedora / RHEL 8+ / CentOS Stream / Rocky / Alma
dnf
sudo dnf install git
RHEL 7 / CentOS 7 (older)
yum
sudo yum install git
Arch / Manjaro / EndeavourOS
pacman
sudo pacman -S git
openSUSE
zypper
sudo zypper install git
Alpine
apk
apk add git
Gentoo
emerge
sudo emerge --ask --verbose dev-vcs/git
Verify the installation
git --version # Example: git version 2.43.0
First-time configuration
Tell Git who you are
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
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
# 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 installUpdating Git
Debian/Ubuntu:
sudo apt update && sudo apt upgrade gitFedora:
sudo dnf upgrade gitArch:
sudo pacman -Syu gitopenSUSE:
sudo zypper update gitAlpine:
apk upgrade git
Common problems
E: Unable to locate package giton Ubuntu — your apt sources are stale. Runsudo apt updatefirst.Permission denied — never run
gititself withsudo. Permission errors usually mean the working directory belongs to root, not you. Fix withsudo 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
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\]\$ '