How to Install Git on Linux (Ubuntu, Debian, Fedora, RHEL, Arch)

Scenario:
Make
: Git
Operating System: Linux [Ubuntu, Debian, Linux Mint, Fedora, RHEL, Rocky Linux, AlmaLinux, CentOS, Arch Linux, openSUSE]
Mode: CLI [Terminal]
Description: In this article, we will discuss a stepwise method of how to install Git on Linux, verify the installation, and configure it for first use, including your name, email and an SSH key for GitHub.

Git is a free, open-source version control system that tracks changes in your code and lets many people work on the same project. GitHub is an online service that hosts Git repositories. You install Git on your computer, and then use it to work with GitHub, GitLab, Bitbucket or any other Git server.

Using Windows instead? Follow How to Install Git on Windows Machines.

Prerequisites

  • A Linux computer or server with an internet connection.
  • A user account with sudo (administrator) rights.
  • Access to a terminal. On most desktops, press Ctrl + Alt + T to open one.

Step 1: Check Whether Git Is Already Installed

Many Linux distributions include Git by default. Run:

git --version

If you see something like git version 2.43.0, Git is already installed and you can skip to Step 4. If you see command not found, continue with Step 2.

Step 2: Install Git

Use the command for your Linux distribution. Enter your password when prompted.

DistributionInstall Command
Ubuntu, Debian, Linux Mintsudo apt update && sudo apt install git -y
Fedora, RHEL 8+, Rocky Linux, AlmaLinuxsudo dnf install git -y
CentOS 7 / RHEL 7sudo yum install git -y
Arch Linux, Manjarosudo pacman -S git
openSUSEsudo zypper install git
Alpine Linuxsudo apk add git

For example, on Ubuntu:

$ sudo apt update && sudo apt install git -y
[sudo] password for edledge:
Reading package lists... Done
...
Setting up git (1:2.43.0-1ubuntu7) ...
Processing triggers for man-db ...

Important Note: The apt update part refreshes the package list first. Skipping it is the most common cause of the error “Unable to locate package git”.

Optional: Install the Latest Git Version on Ubuntu

The version in Ubuntu’s standard repositories can be a little older. To get the newest stable release, use the official Git maintainers’ PPA:

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

Step 3: Verify the Installation

Confirm that Git is installed and see where it is located:

$ git --version
git version 2.43.0

$ which git
/usr/bin/git

Step 4: Set Your Name and Email

Git records your name and email with every commit, so set them before you start working. Use the same email address as your GitHub account if you use GitHub:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

The –global option applies the setting to every repository for your user. To use a different name or email for one project only, run the same command inside that project folder without –global.

Step 5: Set Useful Defaults (Recommended)

These settings are optional, but they save trouble later:

git config --global init.defaultBranch main
git config --global core.editor nano
git config --global pull.rebase false
  • init.defaultBranch main – new repositories use main as the default branch name, matching GitHub.
  • core.editor nano – Git opens the simple nano editor for commit messages instead of vim.
  • pull.rebase false – keeps the standard merge behaviour for git pull and stops Git from showing a warning.

Step 6: Confirm Your Configuration

$ git config --list
user.name=Your Name
user.email=you@example.com
init.defaultbranch=main
core.editor=nano
pull.rebase=false

These settings are saved in the file ~/.gitconfig in your home folder.

Step 7: Connect to GitHub with an SSH Key (Optional)

An SSH key lets you push and pull from GitHub without typing a password or token every time.

Create a new key, replacing the email with your own, and press Enter to accept the default location:

ssh-keygen -t ed25519 -C "you@example.com"

Display the public key and copy the full output:

cat ~/.ssh/id_ed25519.pub

In GitHub, go to “Settings” > “SSH and GPG keys” > “New SSH key”, paste the key and save. Then test the connection:

$ ssh -T git@github.com
Hi edledge! You've successfully authenticated, but GitHub does not provide shell access.

Git is now installed, configured and ready to use. You can clone your first repository with git clone followed by the repository URL.

How to Uninstall Git

# Ubuntu / Debian
sudo apt remove git

# Fedora / RHEL / Rocky / AlmaLinux
sudo dnf remove git

Troubleshooting

  • “Unable to locate package git” – run sudo apt update first, then install again.
  • “git: command not found” after installing – close and reopen the terminal, then check with which git.
  • “Permission denied (publickey)” when connecting to GitHub – make sure you added the .pub key to GitHub and that you are using the SSH URL of the repository (it starts with git@github.com:).
  • “Author identity unknown” when committing – your name and email are not set. Repeat Step 4.

Frequently Asked Questions

Is Git the same as GitHub?

No. Git is the version control software installed on your computer. GitHub is a website that hosts Git repositories online.

Do I need a GitHub account to use Git?

No. Git works fully on your own computer. You only need an account on GitHub, GitLab or a similar service if you want to store or share repositories online.

How do I update Git on Linux?

Run the same install command again after updating the package list, for example sudo apt update && sudo apt install git on Ubuntu. If Git is already installed, this upgrades it to the latest available version.

Other important topics

Source: Knowledge Base, Lab, Git official documentation, GitHub Docs

Disclaimer: This article is for educational purposes only and is not professional financial, medical, or legal advice. It may contain affiliate links, which earn us a small commission at no extra cost to you. See our Disclaimer and Affiliate Disclosure.

Article ID: EA00130

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top