Introduction / Why This Is Needed
Git is a distributed version control system and the de facto standard for software development. Installing Git on Ubuntu is the first and essential step to participating in any project on GitHub, GitLab, or Bitbucket. This guide will walk you through a quick installation from the official repositories and basic configuration so you can immediately start cloning repositories and committing changes.
Prerequisites / Preparation
- Operating System: Ubuntu 22.04 LTS, 24.04 LTS, or a compatible Debian-based distribution (e.g., Linux Mint).
- Access Permissions: A user account with
sudoprivileges to install system packages. - Internet: Access to Ubuntu package repositories.
- Terminal: Any terminal (GNOME Terminal, Konsole, xterm, etc.).
Step 1: Update the Package List
Before installing any new software, it is recommended to update the local package index so your system is aware of the latest available versions.
sudo apt update
This command synchronizes your system with the repositories specified in /etc/apt/sources.list.
Step 2: Install Git
Installing Git from Ubuntu's standard repositories is the simplest and safest method.
sudo apt install git -y
The -y flag automatically confirms the installation prompt. Omit this flag if you prefer to see the confirmation.
Step 3: Verify the Installation
After the installation completes, ensure the git binary is available in your system.
git --version
Expected Output: git version 2.xx.x (the specific version depends on your Ubuntu release).
💡 Tip: If the
gitcommand is not found, try closing and reopening your terminal or runhash -rto clear the command cache.
Step 4: Configure Global Settings
Git requires that every commit contains author information. Configure this once for your entire system.
git config --global user.name "Your Full Name"
git config --global user.email "your.email@example.com"
Replace "Your Full Name" and "your.email@example.com" with your actual details. Use the email address associated with your GitHub/GitLab account.
Step 5: Verify the Configuration
Display the saved global settings to confirm they are correct.
git config --global --list
The output should include the lines user.name=Your Full Name and user.email=your.email@example.com.
Verification of Results
- Version:
git --versiondisplays the current version. - Configuration:
git config --listcontains the correctuser.nameanduser.email. - Practical Test: Create a test repository.
If themkdir ~/test-git && cd ~/test-git git init echo "# Test Project" > README.md git add README.md git commit -m "Initial commit"commitcommand executes without errors and you see commit information (including your name and email), Git is fully ready for use.
Potential Issues
E: Unable to locate package git- Cause: The package list was not updated (
sudo apt updatewas not run) or a repository is not enabled. - Solution: Run
sudo apt updateand repeat the installation. Check that themainrepository is enabled in/etc/apt/sources.list.
- Cause: The package list was not updated (
Permission denied (publickey)when cloning- Cause: This is not a Git installation error. It means you do not have an SSH key configured for server access (GitHub/GitLab).
- Solution: Set up SSH authentication. See the guide Setting up an SSH key for GitHub.
- An outdated version of Git is installed
- Cause: Ubuntu repositories prioritize stability over freshness.
- Solution: To get a newer version, add the official Git PPA:
After this,sudo add-apt-repository ppa:git-core/ppa sudo apt update sudo apt install gitgit --versionwill show a more recent version.
- Error
fatal: unable to access '...': Could not resolve host- Cause: Network connectivity or DNS issues.
- Solution: Check internet access (
ping 8.8.8.8), DNS settings, and proxy configuration (if used).