What the git: command not found Error Means
The git: command not found (or bash: git: command not found) error appears in a Linux terminal when the system cannot find the git executable file in the directories specified in the PATH environment variable. This means that either Git is not installed on the system, or it is installed but its path is not added to PATH, or there are permission issues.
Typically, the error looks like this:
$ git clone https://github.com/user/repo.git
bash: git: command not found
Or (in Zsh):
zsh: command not found: git
Common Causes
- Git is not installed — the most common reason. In a fresh Linux installation (especially minimal distributions), Git is often absent by default.
- Git's path is not added to
PATH— Git is installed in a non-standard location (e.g.,/usr/local/bin), and that directory is missing from thePATHvariable. - Corrupted Git installation — Git files were deleted or partially corrupted.
- Insufficient execution permissions — your user does not have permission to execute the
gitfile (rare, but possible with manual installation). - Shell configuration error — there are incorrect modifications in
~/.bashrc,~/.profile, or~/.zshrcthat have broken thePATH.
Solution 1: Install Git via Package Manager (Recommended)
If Git is not installed, the simplest way is to install it using your distribution's built-in package manager.
For Ubuntu/Debian and derivatives:
sudo apt update
sudo apt install git
For Fedora/RHEL/CentOS 8+:
sudo dnf install git
For CentOS 7 and older, use yum instead of dnf.
For Arch Linux:
sudo pacman -S git
Verify the installation:
After installation, check that the command is available:
git --version
Example output: git version 2.43.0.
Solution 2: Add Git's Path to the PATH Variable
If Git is already installed (check with which git), but the command is not found, its directory is most likely missing from PATH.
- Find the location of the
gitexecutable:sudo find / -type f -name git 2>/dev/null | head -10
Typically, git is located in/usr/bin/git,/usr/local/bin/git, or/opt/git/bin/git. - Identify the directory containing
git(e.g.,/usr/local/bin). - Add this directory to
PATHin your shell's configuration file.- For Bash (the standard shell in most distributions), edit
~/.bashrc:
Replaceecho 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc/usr/local/binwith your actual directory. - For Zsh, edit
~/.zshrc:echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc
- For Bash (the standard shell in most distributions), edit
- Apply the changes:
source ~/.bashrc # or source ~/.zshrc - Verify:
echo $PATH which git
💡 Tip: Ensure the directory is added at the beginning of
PATH(as in the example above) if you want your version of git to take priority over the system version.
Solution 3: Check and Fix Permissions
If Git is installed in system directories (e.g., /usr/bin), but the command doesn't work due to permissions, do the following:
- Check permissions on the
gitfile:ls -l $(which git 2>/dev/null || echo "/usr/bin/git")
Example output:-rwxr-xr-x 1 root root 12M Jan 15 12:34 /usr/bin/git
Permissions-rwxr-xr-x(755) mean all users can execute the file. - If execution permission (
x) is missing, fix it:sudo chmod +x $(which git) - If the file belongs to another user (unlikely for system packages), check if the installation is corrupted. It's better to reinstall Git (Solution 1).
Prevention
- Always install Git via your distribution's official package manager. This ensures correct
PATHintegration and dependency management. - Never move or delete Git files manually after installation.
- When configuring
PATHmanually, check the syntax and avoid duplicate directories. Useecho $PATHto review the current value. - After changes to
~/.bashrc/~/.zshrc, always runsourceor restart the terminal. - Keep Git updated regularly through the package manager (
sudo apt upgrade git,sudo dnf update git).
FAQ
What if which git returns nothing, but git --version works?
This may mean git is in a PATH directory, but which doesn't find it due to aliases or functions. Check if git is an alias: type git. If it is an alias, the settings are in ~/.bashrc/~/.zshrc.
Can I install Git only for the current user?
Yes, you can compile from source and install to ~/.local. Then add export PATH="$HOME/.local/bin:$PATH" to ~/.bashrc. But for most users, using the system package manager is simpler.
Why is Git still not found after installing via apt?
This can happen if you use a non-standard shell or a session that doesn't load the profile. Check if ~/.profile or ~/.bashrc is being loaded. You can add the path to ~/.profile (which loads more frequently) or to /etc/profile.d/git.sh for all users.
How to completely remove Git and reinstall?
- Ubuntu/Debian:
sudo apt purge git && sudo apt install git - Fedora:
sudo dnf remove git && sudo dnf install git - Arch:
sudo pacman -Rns git && sudo pacman -S gitAfter reinstalling, verify withgit --version.