How to Install Git on Ubuntu: A Complete Step-by-Step Guide
Git is the world's most widely used version control system — and for good reason. Whether you're managing code, tracking changes to configuration files, or collaborating with a team, Git gives you a structured, reliable way to handle file history. Installing it on Ubuntu is straightforward, but there are a few paths to get there, and which one makes sense depends on your specific setup and requirements.
What Git Actually Does (and Why It Matters on Ubuntu)
Before diving into commands, it's worth understanding what you're installing. Git operates as a distributed version control system, meaning every developer or machine has a full copy of the project history — not just the latest snapshot. This makes it fast, offline-capable, and resilient.
On Ubuntu specifically, Git integrates tightly with the terminal and is a prerequisite for enormous amounts of developer tooling — package managers, deployment scripts, open-source project contribution workflows, and more. If you're setting up a development environment on Ubuntu, Git is typically one of the first tools installed.
The Two Main Installation Methods
There are two practical ways to install Git on Ubuntu, and they differ in an important way: version currency.
Method 1: Install Git via APT (Ubuntu's Default Package Manager)
This is the most common approach and works well for most users.
Open your terminal and run:
sudo apt update sudo apt install git That's the core of it. The apt update command refreshes your package index so Ubuntu knows what's available, and apt install git pulls down and installs Git from Ubuntu's official repositories.
To confirm the installation worked:
git --version You'll see output like git version 2.x.x — the exact number depends on what Ubuntu's repositories currently offer.
The tradeoff here: Ubuntu's APT repositories tend to carry a slightly older, stable version of Git. For most users — especially those doing general development, learning Git, or working with existing projects — this version is perfectly capable. It includes all core functionality.
Method 2: Install Git via the Official Git PPA
If you need a more recent version of Git — say, because a project requires a specific feature introduced in a newer release, or you want to stay current with upstream changes — you can add Git's official PPA (Personal Package Archive):
sudo add-apt-repository ppa:git-core/ppa sudo apt update sudo apt install git This points Ubuntu to a repository maintained by the Git project itself, which typically tracks closer to the latest stable release.
After installation, verify with:
git --version The version number here should be notably higher than what the default APT method provides.
Initial Configuration After Installing Git 🛠️
Installing Git is only half the setup. Before you use it meaningfully, you need to tell Git who you are. This identity gets attached to every commit you make.
git config --global user.name "Your Name" git config --global user.email "[email protected]" You can verify your configuration at any time:
git config --list A few other common configuration options worth knowing:
| Setting | Command | Why It Matters |
|---|---|---|
| Default branch name | git config --global init.defaultBranch main | Aligns with modern Git conventions |
| Default text editor | git config --global core.editor nano | Controls which editor Git opens for commit messages |
| Credential caching | git config --global credential.helper cache | Temporarily stores credentials so you're not re-prompted constantly |
These aren't mandatory to set immediately, but they prevent friction as soon as you start working with remote repositories.
Installing Git on WSL (Ubuntu on Windows)
If you're running Ubuntu through Windows Subsystem for Linux (WSL), the installation process is identical to native Ubuntu. Open your WSL terminal and follow either method above. Git installed inside WSL operates within the Linux environment — it's separate from any Git installation you may have on the Windows side.
One variable to be aware of: line endings. Files edited in Windows and committed from WSL can sometimes carry CRLF line endings instead of the Unix-standard LF. You can configure Git to handle this:
git config --global core.autocrlf input This tells Git to normalize line endings on commit, which reduces noise in diffs and avoids compatibility issues in cross-platform projects.
Checking for an Existing Installation
On some Ubuntu systems — particularly those that have had development tools installed previously — Git may already be present. Before running any install commands, it's worth checking:
git --version If Git is already installed, you'll get a version number. If it's not, you'll see a "command not found" message and Ubuntu will often suggest the install command automatically.
What Affects Which Method Is Right for You 🔍
The version gap between APT's default offering and the PPA matters differently depending on your situation:
- Learning Git or general development: The default APT version handles everything you're likely to encounter. Version differences rarely surface at this level.
- Open-source contribution or professional development teams: Some projects or CI/CD pipelines specify minimum Git versions. Checking those requirements first tells you whether the PPA is necessary.
- System administration or server environments: Stability often takes priority over currency. The default APT version gets security updates through Ubuntu's standard channels, which can be preferable in managed environments.
- Ubuntu version: Newer Ubuntu LTS releases (like 22.04 or 24.04) ship with more recent Git versions than older LTS releases. The gap between APT and PPA versions narrows on newer systems.
Understanding which of these profiles fits your situation — and what version of Ubuntu you're running — is what actually determines whether the simpler APT method is sufficient or whether the PPA route is worth the extra step.