How to Install Git on Rocky Linux 10, 9 and 8

Install Git on Rocky Linux 10, 9 and 8 using DNF or source compilation. Covers configuration, repository management, updates.

Last updatedAuthorJoshua JamesRead time7 minGuide typeRocky Linux

Rocky Linux keeps Git in AppStream, so most systems can add version control with one DNF command and normal package updates. To install Git on Rocky Linux, use the repository package unless a project specifically requires a newer upstream release than the distro branch provides.

Rocky Linux 10 and 9 currently provide Git 2.47.x, while Rocky Linux 8 provides Git 2.43.x. The source-build path uses the official kernel.org tarball for Git 2.54.0 when you need the current upstream release instead of the AppStream package.

Install Git on Rocky Linux

Choose a Git Installation Method

Most users should install Git from Rocky AppStream because DNF handles updates, dependencies, and removal. Source compilation is useful for a newer Git release, but it shifts updates and cleanup to you.

MethodSourceCurrent VersionUpdatesBest For
DNF packageRocky AppStream2.47.x on Rocky Linux 10 and 9, 2.43.x on Rocky Linux 8Handled by DNF upgradesMost workstations, servers, and CI hosts
Source buildOfficial kernel.org Git archive2.54.0 in this workflowManaged by update-git-sourceSystems that need a newer upstream Git release
Optional GUI toolsRocky AppStream packages git-gui and gitkMatches the AppStream Git branchHandled by DNF upgradesUsers who need Git GUI or repository history browsing

These commands apply to Rocky Linux 10, 9, and 8. Package versions differ by major release, but the DNF install, source build, configuration, troubleshooting, update, and removal flow stays the same.

Update Rocky Linux Before Installing Git

Refresh package metadata and apply pending updates before installing Git. This reduces dependency conflicts and makes sure DNF uses current repository data.

sudo dnf upgrade --refresh

Commands that start with sudo require an administrator account. If repository metadata downloads slowly, tune DNF first with the Rocky-specific steps to increase DNF speed on Rocky Linux.

Install Git with DNF

Install the standard Git package from Rocky AppStream with DNF:

sudo dnf install git

DNF resolves the required dependencies and prompts for confirmation. Accept the transaction when the package list matches your system.

Verify the DNF Git Package

Check the installed Git version after DNF finishes:

git --version

Rocky Linux 10 and 9 currently return:

git version 2.47.3

Rocky Linux 8 currently returns:

git version 2.43.7

If your system prints a Git version, the repository install is complete. Continue with configuration, or skip to the source-build method only if you need the newer upstream release.

Install Optional Git GUI Tools

The base git package does not install the optional GUI tools. Install git-gui and gitk separately if you need a graphical commit interface or history browser:

sudo dnf install git-gui gitk

After installation, launch them with git gui from a repository or gitk from a graphical desktop session.

Build Git from Official Source

Build from source only when the AppStream package is too old for your workflow. The helper below installs Git into a versioned /usr/local/git-<version> prefix, then points /usr/local/bin/git at that managed tree.

Install Build Dependencies

Install the compiler toolchain and libraries Git needs for HTTPS remotes, localization, compression, archive extraction, signature verification, and Perl-based helper tools. The group_package_types=mandatory option installs the required build tools without pulling in the optional AppStream Git package from the Development Tools group.

sudo dnf groupinstall "Development Tools" --setopt=group_package_types=mandatory
sudo dnf install curl ca-certificates gnupg2 tar xz libcurl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker

Create the Git Source Update Helper

Create a reusable update-git-source command. It resolves the latest stable Git source release from kernel.org unless you pass a specific version, verifies Junio C Hamano’s signing key, compiles Git, and refuses to overwrite a custom non-symlinked /usr/local/bin/git file.

sudo tee /usr/local/bin/update-git-source > /dev/null <<'SCRIPT_EOF'
#!/usr/bin/env bash
set -euo pipefail

KEY_URL="https://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git/plain/keys/20D04E5A713660A7.asc"
KEY_ID="20D04E5A713660A7"
KEY_FINGERPRINT="96E07AF25771955980DAD10020D04E5A713660A7"
BASE_URL="https://www.kernel.org/pub/software/scm/git"
BUILD_DIR="$HOME/git-source-build"
GNUPG_DIR="$BUILD_DIR/gnupg"
BASE_PREFIX="/usr/local"
CURRENT_LINK="$BASE_PREFIX/git-current"
BIN_LINK="$BASE_PREFIX/bin/git"

if [ "$(id -u)" -eq 0 ]; then
  echo "Run update-git-source as your normal user; it uses sudo only for installation."
  exit 1
fi

for cmd in awk curl gcc gpg grep make sed sort tar xz; do
  if ! command -v "$cmd" >/dev/null 2>&1; then
    echo "Error: $cmd is required. Install the source-build dependencies first."
    exit 1
  fi
done

if [ -n "${1:-}" ]; then
  LATEST_VERSION="${1#v}"
else
  LATEST_VERSION=$(curl -fsSL "$BASE_URL/" | grep -Eo 'git-[0-9]+\.[0-9]+\.[0-9]+\.tar\.xz' | sed -E 's/git-([0-9.]+)\.tar\.xz/\1/' | sort -Vu | tail -n 1)
fi

if ! [[ "$LATEST_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  echo "Error: could not resolve a stable Git source version."
  exit 1
fi

CURRENT_VERSION="$("$CURRENT_LINK/bin/git" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1 || true)"
CURRENT_VERSION="${CURRENT_VERSION:-none}"

echo "Current source Git version: $CURRENT_VERSION"
echo "Latest Git version: $LATEST_VERSION"

if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
  echo "Already up to date."
  exit 0
fi

if [ -e "$BIN_LINK" ] && [ ! -L "$BIN_LINK" ]; then
  echo "Error: $BIN_LINK already exists and is not a symlink."
  echo "Move that file before running the source-build updater."
  exit 1
fi

if [ -e "$CURRENT_LINK" ] && [ ! -L "$CURRENT_LINK" ]; then
  echo "Error: $CURRENT_LINK already exists and is not a symlink."
  echo "Move that path before running the source-build updater."
  exit 1
fi

TARGET_PREFIX="$BASE_PREFIX/git-$LATEST_VERSION"
if [ -e "$TARGET_PREFIX" ]; then
  echo "Error: $TARGET_PREFIX already exists but is not the active source build."
  echo "Move or remove that directory before reinstalling this Git version."
  exit 1
fi

ARCHIVE="git-${LATEST_VERSION}.tar.xz"
SIGNATURE="git-${LATEST_VERSION}.tar.sign"
KEY_FILE="$BUILD_DIR/${KEY_ID}.asc"
SRC_DIR="$BUILD_DIR/src"

mkdir -p "$BUILD_DIR" "$GNUPG_DIR"
chmod 700 "$GNUPG_DIR"
cd "$BUILD_DIR"

if ! GNUPGHOME="$GNUPG_DIR" gpg --batch --list-keys "$KEY_ID" >/dev/null 2>&1; then
  echo "Importing Git release signing key..."
  curl -fsSL -o "$KEY_FILE" "$KEY_URL"
  GNUPGHOME="$GNUPG_DIR" gpg --batch --import "$KEY_FILE"
fi

ACTUAL_FINGERPRINT=$(GNUPGHOME="$GNUPG_DIR" gpg --batch --with-colons --fingerprint "$KEY_ID" | awk -F: '/^fpr:/ {print $10; exit}')
if [ "$ACTUAL_FINGERPRINT" != "$KEY_FINGERPRINT" ]; then
  echo "Error: Git maintainer key fingerprint did not match the expected value."
  exit 1
fi
echo "Verified Git release key fingerprint: $ACTUAL_FINGERPRINT"

echo "Downloading Git $LATEST_VERSION from kernel.org..."
curl -fsSLO "$BASE_URL/$ARCHIVE"
curl -fsSLO "$BASE_URL/$SIGNATURE"

echo "Verifying signature..."
xz -cd "$ARCHIVE" | GNUPGHOME="$GNUPG_DIR" gpg --batch --verify "$SIGNATURE" -

echo "Extracting source..."
rm -rf "$SRC_DIR"
mkdir -p "$SRC_DIR"
tar -xf "$ARCHIVE" -C "$SRC_DIR" --strip-components=1
cd "$SRC_DIR"

echo "Compiling Git $LATEST_VERSION..."
make -j "$(nproc)" prefix="$TARGET_PREFIX" all

PREVIOUS_TARGET="$(readlink -f "$CURRENT_LINK" 2>/dev/null || true)"

echo "Installing Git $LATEST_VERSION to $TARGET_PREFIX..."
sudo make prefix="$TARGET_PREFIX" install
sudo ln -sfn "$TARGET_PREFIX" "$CURRENT_LINK"
sudo ln -sfn "$CURRENT_LINK/bin/git" "$BIN_LINK"
hash -r

if ! "$BIN_LINK" --version; then
  echo "Error: installed Git did not run correctly."
  if [ -n "$PREVIOUS_TARGET" ]; then
    sudo ln -sfn "$PREVIOUS_TARGET" "$CURRENT_LINK"
  else
    sudo rm -f "$CURRENT_LINK" "$BIN_LINK"
  fi
  exit 1
fi

"$BIN_LINK" --exec-path

if [ -n "$PREVIOUS_TARGET" ] && [ "$PREVIOUS_TARGET" != "$TARGET_PREFIX" ] && [[ "$PREVIOUS_TARGET" == "$BASE_PREFIX"/git-[0-9]* ]]; then
  sudo rm -rf "$PREVIOUS_TARGET"
fi

echo "Source Git update complete."
SCRIPT_EOF
sudo chmod 0755 /usr/local/bin/update-git-source

The helper uses the curl command in Linux for source downloads and stores its temporary build workspace in ~/git-source-build. Keep that directory if you plan to use the helper for future source updates.

Confirm the helper is available from your shell:

command -v update-git-source
/usr/local/bin/update-git-source

Compile and Install Git

Run the helper with the validated source version. It downloads the archive and signature, checks the maintainer fingerprint, verifies the signature against the uncompressed tar stream, builds Git, and updates the managed symlinks.

update-git-source 2.54.0
hash -r

Relevant output includes the signature check, installed version, and Git execution path:

Current source Git version: none
Latest Git version: 2.54.0
Importing Git release signing key...
Verified Git release key fingerprint: 96E07AF25771955980DAD10020D04E5A713660A7
Downloading Git 2.54.0 from kernel.org...
Verifying signature...
gpg: Good signature from "Junio C Hamano <gitster@pobox.com>" [unknown]
git version 2.54.0
/usr/local/git-2.54.0/libexec/git-core
Source Git update complete.

Confirm that your shell finds the source-built Git first:

command -v git
git --version
git --exec-path
/usr/local/bin/git
git version 2.54.0
/usr/local/git-2.54.0/libexec/git-core

GPG may warn that the key is not certified by a trusted signature. That warning is normal on a new system, but the fingerprint must match the value checked by the helper before the build continues.

Configure Git on Rocky Linux

Git needs an author name and email address before you create commits. The global settings apply to new repositories for your user account, while repository-local settings can override them later.

Set Your Git Username and Email

Replace the example values with the name and email address you want recorded in commit metadata:

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

Verify both values:

git config --global --get user.name
git config --global --get user.email
Your Name
your.email@example.com

For per-repository identities, signing details, and common mistakes, see the full walkthrough to configure Git username and email.

Choose a Default Branch Name

Set the default branch name Git uses when you create a new repository:

git config --global init.defaultBranch main

This setting affects new repositories only. Existing repositories can be renamed later with the steps to rename a local and remote Git branch.

Configure HTTPS Credential Caching

Credential caching keeps HTTPS credentials in memory for a limited time, which reduces repeated prompts on personal systems:

git config --global credential.helper 'cache --timeout=14400'

The timeout is in seconds, so 14400 keeps credentials cached for four hours. On shared hosts, use SSH keys or your organization’s credential manager policy instead of a long cache window.

Create a Test Git Repository

Create a small repository to confirm initialization, staging, and commits work correctly:

mkdir -p ~/my-project
cd ~/my-project
git init --initial-branch=main
Initialized empty Git repository in /home/user/my-project/.git/

Add a file and create the first commit:

printf 'hello rocky\n' > README.md
git add README.md
git commit -m "Add initial README"

If Git reports a missing author identity, return to the configuration section and set your global name and email.

Add a remote when you are ready to connect the local repository to a hosting service:

git remote add origin https://github.com/username/repository.git
git remote -v
origin  https://github.com/username/repository.git (fetch)
origin  https://github.com/username/repository.git (push)

Users who prefer GitHub’s command-line workflow can pair Git with the dedicated steps to install GitHub CLI on Rocky Linux.

Troubleshoot Git on Rocky Linux

Fix git Command Not Found After DNF Install

If your shell cannot find Git after installation, first confirm the package state:

bash: git: command not found
rpm -q git
sudo dnf install git
hash -r
git --version

If rpm -q git reports that the package is not installed, the DNF install command restores it. If the package is installed but your shell still cannot find it, opening a new terminal usually clears the stale command cache.

Fix Source Build Showing the Repository Version

A source build can succeed while your shell still finds the old /usr/bin/git path first:

command -v git
git --version
/usr/bin/git
git version 2.47.3

First clear Bash’s command lookup cache and check again:

hash -r
command -v git

If the command still prints /usr/bin/git, a custom shell profile may be putting /usr/bin ahead of /usr/local/bin. Move /usr/local/bin ahead of /usr/bin for the current shell, then make the change persistent for future Bash sessions:

export PATH="/usr/local/bin:$PATH"
hash -r
printf '%s\n' 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc

Run command -v git again. It should print /usr/local/bin/git when the source build is first in PATH.

Fix gitk Command Not Found

The gitk command comes from a separate AppStream package. Install it when you see this error in a graphical session:

zsh: command not found: gitk
sudo dnf install gitk
command -v gitk

Install git-gui as well if you need Git’s graphical commit interface.

Fix GitHub Permission Denied Publickey Errors

SSH remotes fail with a public key error when the remote host does not know your key or your local SSH client is not offering it:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Install the OpenSSH client tools first:

sudo dnf install openssh-clients

Create an Ed25519 key, then add it to your local SSH agent:

ssh-keygen -t ed25519 -C "your.email@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Add the public key from ~/.ssh/id_ed25519.pub to your Git hosting account, then test the SSH connection with ssh:

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

If the repository URL is HTTPS but you want SSH, update the remote URL with git remote set-url origin git@github.com:username/repository.git.

Update or Remove Git on Rocky Linux

Update DNF-Installed Git

Use DNF to update the repository package and its dependencies:

sudo dnf upgrade --refresh git

Running a full system update with sudo dnf upgrade --refresh updates Git at the same time when Rocky publishes a newer package for your release. If you installed git-gui or gitk, DNF updates those packages in the same transaction when updates are available.

Update Source-Compiled Git

Source builds do not update through DNF. Run the helper whenever you want to check kernel.org for a newer stable source release, or pass a specific version after confirming it exists in the official archive. After a successful update, the helper points /usr/local/git-current at the new version and removes the previous article-managed prefix.

update-git-source
hash -r

When your source build already matches the latest stable release, the helper exits without rebuilding:

Current source Git version: 2.54.0
Latest Git version: 2.54.0
Already up to date.

To rebuild a specific release from the official archive, pass the version explicitly:

update-git-source 2.54.0
hash -r

Avoid running source-build updates from cron. Compilation and signature verification can fail because of dependency changes, network failures, or upstream build changes, and you should see that output before a system-wide Git binary changes.

Remove DNF-Installed Git

Remove the AppStream Git package with DNF:

sudo dnf remove git git-core
rpm -q git git-core || true
package git is not installed
package git-core is not installed

If you installed git-gui or gitk, remove those packages separately:

sudo dnf remove git-gui gitk

Remove Source-Compiled Git

Source-compiled Git installs outside RPM tracking, so DNF cannot remove it. Check the active binary and managed prefix before deleting files:

command -v git
git --exec-path
readlink -f /usr/local/git-current 2>/dev/null || true
/usr/local/bin/git
/usr/local/git-2.54.0/libexec/git-core
/usr/local/git-2.54.0

The next commands delete the versioned Git prefix, stable symlink, source workspace, and update helper created in this article. Do not run them if /usr/local/git-current points to a custom Git installation you manage another way.

SOURCE_PREFIX=$(readlink -f /usr/local/git-current 2>/dev/null || true)
case "$SOURCE_PREFIX" in
  /usr/local/git-[0-9]*)
    sudo rm -f /usr/local/bin/git
    sudo rm -f /usr/local/git-current
    sudo rm -rf "$SOURCE_PREFIX"
    ;;
  *)
    echo "No article-managed source Git prefix found."
    ;;
esac
sudo rm -f /usr/local/bin/update-git-source
rm -rf "$HOME/git-source-build"
hash -r

Verify the source-build helper and managed symlink are gone:

test ! -e /usr/local/git-current && echo "source Git symlink removed"
test ! -e /usr/local/bin/update-git-source && echo "update-git-source removed"
command -v git || echo "git command is not available"
source Git symlink removed
update-git-source removed
git command is not available

If the DNF package is still installed, the final command should fall back to /usr/bin/git. If no Git package remains, it should print git command is not available.

Conclusion

Git is ready on Rocky Linux from either AppStream or a verified upstream source build, with identity settings, first repository commands, updates, and cleanup paths in place. For daily workflows, practice how to switch Git branches, recover from mistakes when you undo the last Git commit, or remove tracked files from history with clear Git cache steps.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show our tutorials more often in Top Stories and mark them as preferred in AI Mode and AI Overviews when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<a href="https://example.com">link</a> link
<blockquote>quote</blockquote> quote block

Add to the discussion

Questions, fixes, command output, and version notes help keep this guide current.

Verify before posting: