Recommended Free Tools
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.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
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.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →- 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’sPATH. - An automated process has a different environment. A systemd service, cron job, container entrypoint, deployment runner, or application user can have a shorter
PATHthan 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:
#1 Best Overall
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.
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 gitor 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:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.
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:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute/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:
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:
Rank #4
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.
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
PATHin 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 --versionin 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.
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:
Best Value
/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.
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.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsCommon 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
- Run
command -v gitandgit --versionin a new shell. - Clear the shell’s command cache with
hash -rwhere supported. - Print
PATHand locate the installed executable. - 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.
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
- Read
/etc/os-releaseand identify the package manager. - Run
command -v gitandtype -a gitas the account reporting the error. - If no path is returned, install Git with the matching command from the distribution table, refreshing package metadata when necessary.
- Open a fresh shell, clear command lookup caches where supported, and run
git --version. - If the command still fails, locate the executable and compare its directory with the failing account’s
PATH. - If only an automated process fails, test as its service account and configure an explicit path or absolute executable.
- 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.
Quick Recap
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.




