GeekDas
••7 min read•
GeekdasGeekdas

How to Install Git on Ubuntu (Step-by-Step Guide for Beginners 2026 Guide)

How to Install Git on Ubuntu (Step-by-Step Guide for Beginners 2026 Guide)

Git is the most widely used version control system in the world, and it is an essential tool for anyone writing code, whether you work solo or in a team. If you are wondering how to install Git on Ubuntu, this guide walks you through the whole process: installing Git with apt, verifying it, configuring it properly, and fixing the most common problems.

By the end of this guide you will know how to:

  • Install Git on Ubuntu with the apt install git command

  • Install a newer Git version using the official Git PPA

  • Configure your username, email, default branch and editor

  • Create and test your first repository

  • Update or uninstall Git when needed

  • Troubleshoot common errors

This guide works on Ubuntu 20.04, 22.04, 24.04 and newer, and also on Debian-based distributions such as Linux Mint and Pop!_OS.

What Is Git and Why Do You Need It?

Git is a free, open-source distributed version control system. It tracks every change you make to your files, so you can go back to an earlier version, compare changes, and work with other people on the same project without overwriting each other's work.

Here is why developers rely on it:

  • History and rollback: Every commit is a snapshot you can return to if something breaks.

  • Branching: You can try new features in a separate branch without touching the stable code.

  • Collaboration: Platforms like GitHub, GitLab and Bitbucket are built on Git, so teams can review and merge each other's code.

  • Works offline: Because Git is distributed, you have the full project history on your own machine.

Whether you are building a website, a Python script or a large application, Git is one of the first tools worth setting up.

Prerequisites

Before you start, make sure you have:

  • A computer running Ubuntu (any currently supported version)

  • A user account with sudo privileges

  • An active internet connection

  • A terminal open (press Ctrl + Alt + T)

Step 1: Check Whether Git Is Already Installed

Some Ubuntu installations already include Git. Check first so you do not repeat work:

git --version

If you see something like git version 2.43.0, Git is already installed and you can skip to the configuration step (or the update section if you want a newer version). If you see command not found, continue with the next step.

Step 2: Update the Package List

Always refresh your package index before installing new software. This makes sure Ubuntu knows about the latest version of Git available in its repositories.

sudo apt update

You can also upgrade existing packages while you are at it:

sudo apt upgrade -y

Step 3: Install Git on Ubuntu

Now install Git from the official Ubuntu repository using the apt install git command:

sudo apt install git -y

This completes the Ubuntu install Git process using the default package manager. The -y flag automatically answers "yes" to the confirmation prompt. Apt will also install any dependencies Git needs.

Step 4: Verify the Git Installation

Confirm that Git installed correctly by checking its version:

git --version

You should see output similar to:

git version 2.x.x

This confirms Git is installed and ready to use. You can also check where the binary lives:

which git

Typically this prints /usr/bin/git.

The same method also works on most Debian-based systems, making it one of the easiest ways to install Git on Linux.

Step 5: Configure Your Git Username and Email

Git attaches your name and email address to every commit you make. This matters most when you work with GitHub, GitLab or Bitbucket, because it controls how your commits are attributed.

Set your global username:

git config --global user.name "Your Name"

Set your global email address:

git config --global user.email "youremail@example.com"

Tip: Use the same email address as your GitHub or GitLab account so your commits link to your profile correctly.

Set the default branch name to main for new repositories (this matches GitHub's default):

git config --global init.defaultBranch main

Choose your preferred text editor for commit messages. The default is often Nano, which is beginner-friendly:

git config --global core.editor "nano"

If you prefer VS Code:

git config --global core.editor "code --wait"

Enable colored output so git status and git diff are easier to read:

git config --global color.ui auto

Step 6: Verify Your Git Configuration

To check that your settings were saved, run:

git config --list

You should see your username and email in the output. To check a single value:

git config user.name
git config user.email

Your global settings are stored in a file called .gitconfig in your home directory. You can open it any time:

cat ~/.gitconfig

Step 7: Create and Initialize a Test Repository

To make sure everything works properly, create a test directory and initialize a Git repository:

mkdir git-test
cd git-test
git init

If successful, Git creates a hidden .git directory and prints a confirmation message. Now make your first commit:

echo "# My First Git Project" > README.md
git add README.md
git commit -m "Initial commit"
git log --oneline

If git log shows your commit, your setup is working end to end. You can delete the test folder afterwards with rm -rf ~/git-test.

Installing the Latest Version of Git on Ubuntu (Using the PPA)

The version of Git in Ubuntu's default repositories is stable but is often a few releases behind. If you need newer features or security fixes, you can add the official Git maintainers' PPA:

sudo add-apt-repository ppa:git-core/ppa -y
sudo apt update
sudo apt install git -y

Then confirm the new version:

git --version

If add-apt-repository is not found, install it first with sudo apt install software-properties-common.

Which Method Should You Choose?

Method

Best for

Pros

Cons

Default apt repository

Most beginners and servers

Simple, stable, tested with your Ubuntu release

May not be the newest version

Git PPA

Developers who want recent features

Newer version, still updates through apt

Third-party repository

Build from source

Advanced users who need a specific version

Full control over the version

Manual updates, more steps

For most people, the default apt install git method is the right choice.

How to Update Git on Ubuntu

If you installed Git with apt (default or PPA), updating is simple:

sudo apt update
sudo apt install --only-upgrade git

Git will also be updated whenever you run a full system upgrade with sudo apt upgrade.

How to Uninstall Git on Ubuntu

If you ever need to remove Git, use:

sudo apt remove git

To remove Git along with its configuration files and unused dependencies:

sudo apt purge git
sudo apt autoremove

Note that your personal ~/.gitconfig file and your repositories are not deleted automatically.

Common Errors and How to Fix Them

git: command not found

Git is not installed, or your shell cannot find it. Run sudo apt install git -y and open a new terminal window.

E: Unable to locate package git

Your package list is probably out of date. Run sudo apt update and try again. If it still fails, check your internet connection and your repository settings.

E: Could not get lock /var/lib/dpkg/lock-frontend

Another process, such as Software Updater, is using apt. Wait a few minutes and retry. Avoid deleting the lock file unless you are sure no other package manager is running.

Please tell me who you are when committing

You have not set your name and email yet. Run the two git config --global commands from Step 5.

Permission denied (publickey) when pushing to GitHub

Your SSH key is missing or not added to your account. Setting up SSH correctly fixes this (see the next section).

Set Up SSH for GitHub and GitLab

If you plan to work with remote repositories on platforms like GitHub or GitLab, it is highly recommended to use SSH authentication instead of HTTPS. SSH allows secure communication between your system and the remote server without entering your password every time. Follow our complete step-by-step guide on how to set up SSH in Ubuntu and clone repositories using SSH to configure keys and connect your Git account securely.

Was this article helpful?

Comments

Leave a comment

Loading comments...

Frequently Asked Questions

How do I install Git on Ubuntu?
Open a terminal and run sudo apt update followed by sudo apt install git -y. Then check the installation with git --version.
What is the command to install Git in Ubuntu?
sudo apt install git
How do I check if Git is installed on Ubuntu?
git --version If installed, it will display the Git version number.
Does the same method work to install Git on Linux?
Yes, this method works for Debian based Linux distributions. For other Linux systems like CentOS or Fedora, you may need to use yum or dnf instead of apt.
Why should I configure Git after installation?
Git requires your username and email to track commits and collaborate on platforms like GitHub or GitLab.
How do I set up Git in Ubuntu after installation?
git config --global user.name "Your Name" git config --global user.email "youremail@example.com"
Is Git free to use?
Yes. Git is free and open source under the GNU General Public License.

Related Articles