Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
VGSources
Blog

How to Fix “git: command not found” on a Linux Server

A distribution-by-distribution guide to installing Git on Linux servers, verifying it, repairing PATH problems, and fixing services that use a different environment.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The error means the shell cannot resolve an executable named git. Either Git is not installed, its directory is missing from the failing account’s PATH, or a service is running with a different environment than your administrator shell. Identify the distribution, install Git with its supported package manager, start a fresh shell, and verify with git --version. If only an automated job fails, inspect that job’s service account and use Git’s absolute path.

What “git: command not found” actually means

A shell prints git: command not found when command lookup fails. The shell searches each directory listed in PATH for an executable called git. The message does not by itself prove that Git is absent. Three situations produce the same symptom:

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Git is not installed. No Git executable exists in the server’s standard binary directories.
  • Git is installed but hidden from this account. The executable may be in /usr/local/bin, a custom prefix, or another directory not included in the account’s PATH.
  • An automated process has a different environment. A systemd service, cron job, container entrypoint, deployment runner, or application user can have a shorter PATH than an administrator’s interactive login shell.

Do not begin by copying a binary from another machine or by changing global shell files. First establish which of those conditions applies. The Git project describes the distribution package manager as the easiest Linux installation route in its Git installation guide.

Run these checks before changing anything

1. Identify the distribution

Read the local release metadata rather than guessing from the hosting provider or kernel version:

cat /etc/os-release

Look for fields such as ID, ID_LIKE, and VERSION_ID. They tell you whether to use APT, DNF/YUM, Pacman, Zypper, APK, Portage, or Nix. Minimal images can omit a package manager entirely; in that case, confirm whether you are inside a deliberately stripped container before selecting a source build.

2. Ask the current shell whether it can find Git

command -v git
type -a git

If either command prints a path, Git is discoverable in this shell and the original failure may have come from a different account, shell, or service. If both commands print nothing (or report an error), continue with the package check and installation steps below.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Check the current search path

printf '%sn' "$PATH"

A normal system installation commonly places Git in a directory already listed in PATH. A custom installation may place it under /usr/local/bin or a prefix such as /opt/git/bin. Do not assume that a path visible to root is also visible to an unprivileged account.

4. Check the package database when appropriate

Use your distribution’s package query tools if you suspect Git is installed but cannot be found. The exact query command differs by distribution; the decisive test remains whether the intended account can run command -v git and git --version after installation.

Install Git with the server’s native package manager

Choose the row that matches /etc/os-release. Commands shown with sudo require an account authorized to install packages; on a root shell, omit sudo. These commands and the distribution coverage are documented by the Git project’s Linux installation page.

Distribution Supported installation command Important qualification
Debian sudo apt-get install git Refresh APT metadata first if the image’s package lists are stale or missing.
Ubuntu sudo apt-get install git
or sudo apt install -y git
Ubuntu also documents an optional Snap route; the native APT package is usually simpler for servers.
Fedora 22 and later sudo dnf install git Older Fedora releases use the equivalent yum guidance.
Arch Linux sudo pacman -S git Use the normal Pacman workflow for synchronizing repositories when the local database is out of date.
openSUSE sudo zypper install git Confirm that the configured repositories match the server’s openSUSE release.
Alpine Linux apk add git Run as root or through the privilege mechanism enabled in the image.
Gentoo emerge --ask --verbose dev-vcs/git Portage resolves the package and its USE-flag/dependency requirements.
Nix or NixOS nix-env -i git Installation is tied to the Nix profile of the account that runs the command.

Debian and Ubuntu details

On a Debian-family server, update package metadata when the image was newly created, has been offline, or reports that package lists are unavailable:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt-get update
sudo apt-get install git

Ubuntu’s documentation also shows the noninteractive form:

sudo apt install -y git

Ubuntu documents sudo snap install git-scm as an optional package path in its Git version-control documentation. Snap changes where the application is mounted and how it is updated, so account for that layout if an automated service must call Git. For a conventional server installation, keep one package source and document it rather than installing duplicate copies.

Fedora and related systems

Fedora 22 and newer use DNF:

sudo dnf install git

Older Fedora guidance uses yum. Enterprise distributions derived from Red Hat can ship different repository sets and Git versions; use the package manager available on that specific release instead of forcing Fedora commands onto it.

Arch, openSUSE, Alpine, Gentoo, and Nix

Use the command in the table exactly as the distribution expects. Alpine’s apk and Gentoo’s Portage are especially common in minimal or specialized images, where a full interactive shell may not be present. With Nix, the executable is placed in the invoking user’s profile; a service account will not automatically inherit an administrator’s Nix profile.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reload command lookup and verify the installation

After the package manager completes, do not rely solely on its success message. Verify from the same account and shell that will use Git:

command -v git
git --version

The Git command should print a path and a version string. The Git project’s installation guidance uses version output as the practical confirmation that Git is available. If the shell still reports the old error immediately after installation, open a new login shell. Some shells cache failed or successful command lookups; in shells that support it, clear the cache with:

hash -r

Then rerun command -v git. A fresh shell also reloads profile files that add standard binary directories to PATH. If a package manager installed Git but command -v git remains empty, continue with the path checks rather than reinstalling repeatedly.

When Git is installed but the shell still cannot find it

Locate the executable directly

Use the path printed by the package manager’s file list or inspect likely directories as an administrator. For a custom installation, check the prefix you selected. Once you know the full path, run it directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
/full/path/to/git --version

If the absolute command works but git --version does not, the installation is functional and the problem is exclusively PATH resolution.

Compare administrator and application environments

Check the identity and environment of the account that receives the error:

id
printf '%sn' "$PATH"
command -v git

Then compare it with the administrator’s shell. A path such as /usr/local/bin or /opt/git/bin must be present for that account, either through its login profile or the service configuration. Avoid editing /etc/profile merely to fix one application; a narrowly scoped service or account setting is easier to audit and less likely to affect unrelated jobs.

Make a custom prefix available deliberately

If you installed Git under /opt/git, its binaries may be under /opt/git/bin. Add that directory to the environment used by the process, or call the executable by its absolute path. For an interactive account, place the export in the profile file that account actually reads and then start a new login shell:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
export PATH="/opt/git/bin:$PATH"
command -v git
git --version

Do not add a directory until you have confirmed that it contains the intended executable. Keeping the prefix and the account that needs it documented prevents a later administrator from removing a “unused” directory and silently breaking deployments.

Fix failures limited to systemd, cron, CI, or another service

A successful administrator test does not prove that a daemon can resolve Git. Services often run as a dedicated user with a deliberately minimal environment and do not read your interactive shell’s startup files.

Test as the service account

Replace appuser with the account named by the service or job:

sudo -u appuser env -i PATH=/usr/local/bin:/usr/bin:/bin command -v git
sudo -u appuser env -i PATH=/usr/local/bin:/usr/bin:/bin git --version

This test removes inherited variables and approximates a restricted service environment. If it fails, either include the directory containing Git in the service’s explicit PATH or use the absolute path returned by an administrator’s command -v git. Ensure the service account can execute the file and traverse every parent directory; a path that exists but is inaccessible still produces a failed job.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use an explicit executable path in systemd

For a systemd unit, an absolute command in ExecStart avoids dependence on an interactive profile. Alternatively, define a narrowly scoped Environment=PATH=... value in the unit or an environment drop-in. After changing a unit, reload unit definitions and restart the service, then inspect its status and journal for the account and command actually used. Do not assume that restarting the application has re-read a changed unit file.

Check cron, containers, and deployment runners

  • Cron: supply the required PATH in the crontab or invoke Git by absolute path. Cron generally does not load the same profile as an SSH login.
  • Containers: install Git in the image that executes the job. Installing it on the host does not place it inside an isolated container filesystem.
  • CI or deployment runners: identify the runner account and the image or worker where the command executes. Verify git --version in that execution context, not only on the controller host.

These checks separate an installation problem from an environment problem. If the service account can run git --version but the application still fails, inspect the application’s working directory, permissions, and command construction next; command discovery is no longer the blocker.

Build Git from source only when a package is unsuitable

The native package is normally the lowest-maintenance choice. A source build is appropriate when the configured repositories do not provide Git, the available package is too old for a documented requirement, or you need a controlled installation prefix. The Pro Git installation chapter covers package installation, distribution-specific dependency examples, and the standard ./configure, make, and make install workflow. The Git Linux page also identifies source compilation as an option for RHEL and related distributions.

Prepare dependencies and a build location

Install the compiler and development libraries listed for your distribution in the Pro Git chapter before configuring Git. Dependency names differ between DNF- and APT-based systems, and a minimal server image may lack even basic build tools. Keep source code in a dedicated, writable build directory and decide who will maintain the resulting files.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure, compile, and install

./configure --prefix=/opt/git
make
sudo make install

The --prefix value is an example of a controlled location; choose a prefix that matches your filesystem policy. Record the exact prefix, source version, compiler dependencies, and installation date. The install step may require elevated privileges when the prefix is not writable by the build user.

Expose the custom build to every required account

After installation, verify the binary directly and then through the target environment:

/opt/git/bin/git --version
PATH="/opt/git/bin:$PATH" git --version

For a service, configure its account or unit with /opt/git/bin in PATH, or reference /opt/git/bin/git explicitly. A source build transfers update responsibility to you: track security fixes, repeat the dependency process for upgrades, and remove obsolete versions deliberately. Do not leave an undocumented custom binary beside a package-managed copy, because different accounts may then run different Git versions.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose between a package and a source build

Decision factor Distribution package Source build
Availability Available through the server’s configured native repositories. Useful when repositories lack Git or provide an unsuitable version.
Version selection Constrained by the distribution release and enabled repositories. Selected by the source version and your build process.
Privileges Usually requires package-install privileges; execution normally works for ordinary users. Compilation can run unprivileged, but installation into a shared prefix may require elevated privileges.
Maintenance Updates, dependency tracking, and file ownership follow the distribution package system. You must track updates, dependencies, the prefix, and removal or replacement of old builds.
Environment Usually lands in a standard directory already covered by system paths. You must add the chosen bin directory to each interactive or service environment.

For a normal server, use the package route first. Select source installation only when its additional operational cost solves a specific repository or version requirement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common failure modes and precise fixes

“sudo: command not found” or insufficient privileges

The issue may be the privilege tool rather than Git. Log in with an authorized administrator account, switch to a root shell according to your organization’s policy, or ask the system owner to install the package. Do not grant broad administrative rights just to make one installation command work.

“Unable to locate package git” or an equivalent package error

Confirm the distribution with cat /etc/os-release, refresh repository metadata where that distribution requires it, and verify that the correct repositories are enabled for the release. Do not substitute a command from another distribution because the names look similar. If the image intentionally has no repositories, use an approved image that includes Git or follow the documented source-build route.

The package command succeeds, but the old error remains

  1. Run command -v git and git --version in a new shell.
  2. Clear the shell’s command cache with hash -r where supported.
  3. Print PATH and locate the installed executable.
  4. Test as the account that actually failed, not only as root.

If the absolute path works, correct the environment rather than reinstalling Git.

Interactive SSH works, but a scheduled job fails

Compare the job’s account and PATH with the SSH session. Cron, systemd, containers, and CI workers can all omit profile changes. Set an explicit path in the job or call the absolute executable, then restart or reload the scheduler as required by that system.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Two Git installations produce confusing results

Run type -a git to list every discoverable copy. Decide which installation should be authoritative, remove or isolate obsolete copies according to your package policy, and make the selected path consistent for interactive users and services. Verify again with git --version under each required account.

A source-built Git disappears after maintenance

Package cleanup will not manage files under a custom prefix, while a manual deletion can remove the only copy used by a service. Keep an inventory entry for the prefix and owner, include it in configuration management, and test the service after upgrades or image rebuilds.

A repeatable server runbook

  1. Read /etc/os-release and identify the package manager.
  2. Run command -v git and type -a git as the account reporting the error.
  3. If no path is returned, install Git with the matching command from the distribution table, refreshing package metadata when necessary.
  4. Open a fresh shell, clear command lookup caches where supported, and run git --version.
  5. If the command still fails, locate the executable and compare its directory with the failing account’s PATH.
  6. If only an automated process fails, test as its service account and configure an explicit path or absolute executable.
  7. Use a source build only for a defined repository, version, or prefix requirement; record dependencies and maintenance ownership.

This sequence distinguishes absence, path visibility, and service-environment problems without changing more of the server than necessary.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.