Git Notes
Step-by-step guide to install Git on Ubuntu, Debian, Fedora, CentOS, and Arch Linux with post-installation configuration, verification, and troubleshooting for all major Linux distributions.
Git is essential for modern software development. This comprehensive guide covers installation on all major Linux distributions, configuration, verification, and troubleshooting.
Installation by Distribution
Ubuntu / Debian (APT-based)
# Update package cache
sudo apt update
# Install Git
sudo apt install git
# Verify installation
git --versionOutput:
Install Latest Version via PPA
# Add Git Core PPA
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
# Verify
git --version
# Output: git version 2.44.0Fedora (DNF)
sudo dnf install git
git --versionCentOS / RHEL
# CentOS 7
sudo yum install git
# CentOS 8+
sudo dnf install gitArch Linux
sudo pacman -S git
git --versionBuild from Source
# Install dependencies
sudo apt install build-essential libcurl4-gnutls-dev libexpat1-dev gettext libssl-dev libz-dev
# Download and compile
cd /tmp
wget https://kernel.org/pub/software/scm/git/git-2.44.0.tar.gz
tar -zxf git-2.44.0.tar.gz
cd git-2.44.0
make configure
./configure --prefix=/usr/local
make all
sudo make install
git --versionPost-Installation Configuration
Configure Your Identity
git config --global user.name "Your Full Name"
git config --global user.email "your@email.com"
git config --global init.defaultBranch main
git config --global core.editor "nano"Advanced Configuration
# Line ending handling
git config --global core.autocrlf input
# Credential storage
git config --global credential.helper store
# Merge strategy
git config --global pull.rebase true
# Color output
git config --global color.ui trueVerify Configuration
git config --list
# Specific values
git config --global user.name
git config --global user.emailOutput:
SSH Key Setup
# Generate SSH key
ssh-keygen -t ed25519 -C "your.email@example.com"
# Start SSH agent
eval "$(ssh-agent -s)"
# Add key
ssh-add ~/.ssh/id_ed25519
# Display public key
cat ~/.ssh/id_ed25519.pubVerification
Test Installation
git --version
which git
mkdir test-repo && cd test-repo
git init
git config local user.name "Test User"
git config local user.email "test@example.com"
echo "Hello Git" > README.md
git add README.md
git commit -m "Initial commit"
git logDistribution Comparison
| Distribution | Manager | Command | Latest Support |
|---|---|---|---|
| Ubuntu/Debian | APT | sudo apt install git | Via PPA |
| Fedora | DNF | sudo dnf install git | Usually current |
| CentOS 7 | YUM | sudo yum install git | Older versions |
| Arch | Pacman | sudo pacman -S git | Cutting edge |
Troubleshooting
"git: command not found"
# Check if installed
which git
# Verify installation
apt list --installed | grep git
# Update PATH
export PATH="/usr/local/bin:$PATH"Permission Denied
# Always use sudo for system-wide install
sudo apt install git
# Never use sudo for config
git config --global user.name "Name" # CorrectOld Version in Repository
# Check version
git --version
# Use PPA (Ubuntu)
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt upgrade gitInterview Q&A
Q1: How do you install the latest Git on Ubuntu?
A: Add the official Git Core PPA with sudo add-apt-repository ppa:git-core/ppa, update with sudo apt update, then install with sudo apt install git. Default repositories lag behind releases. Verify with git --version.
Q2: What commands run immediately after Git installation?
A: Configure identity with git config --global user.name and user.email. Set default branch with init.defaultBranch main. Choose editor with core.editor. These are required before commits.
Q3: Package manager vs building from source?
A: Package manager is quick and simple but provides older versions. Building from source takes longer but gives latest features and security patches. For most developers, package manager version suffices.
Q4: How to verify proper Git installation?
A: Run git --version, which git, git config --list, initialize test repo with git init, and make test commit. Run git help to verify documentation.
Q5: What if "git: command not found" after installation?
A: Verify installation with apt list --installed | grep git. Check PATH with echo $PATH. Try /usr/bin/git --version. Reinstall if needed with sudo apt install --reinstall git.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Install Git on Linux - Complete Setup Guide.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, setup, install, linux, install git on linux - complete setup guide
Related Git & GitHub Topics