
How to Fix Command Not Found Errors in Linux, macOS, and Windows
One of the first barriers developers face when configuring a local coding environment is the terminal error: "command not found" (on Linux or macOS) or "is not recognized as an internal or external command" (on Windows).
This error occurs when you attempt to run a tool (such as node, python, git, or docker) and the shell interface fails to locate the corresponding executable program on your system.
In this guide, we will analyze how operating systems search for binaries, check if tools are installed, and configure the PATH environment variable across different shells.
How Your Shell Locates Commands
When you type a command (e.g., git status) and press Enter, the operating system does not scan your entire hard drive for the git program. That would be too slow.
Instead, the OS looks at a system variable named PATH.
The PATH variable contains a list of directory paths separated by colons (:) on Unix systems, or semicolons (;) on Windows. The shell checks these folders one by one. If it fails to find the executable program inside any of them, it halts and reports the "command not found" error.
Step 1: Verify Installation
Ensure the software is actually installed on your machine. You can trace its directory using location tools:
- Linux / macOS:
which git
# Or:
whereis node- Windows (PowerShell):
Get-Command gitIf these tools return blank lines, the software is missing. Download and run the appropriate installer. If they return a valid file path (e.g., /usr/local/bin/node or C:\Program Files\Git\cmd\git.exe), the software is installed, but the folder is missing from your PATH.
Step 2: Configure PATH on Linux and macOS
On Unix systems, you add folders to your path inside your shell configuration file (typically ~/.bashrc for Bash, or ~/.zshrc for Zsh on newer macOS versions).
For Zsh (macOS Default)
- Open your profile configuration file:
nano ~/.zshrc- Add the directory containing your binary tool at the bottom (replace
/custom/bin/pathwith the actual folder directory):
export PATH=$PATH:/custom/bin/path- Save the file (Ctrl+O, then Ctrl+X) and refresh the active shell:
source ~/.zshrcFor Bash (Ubuntu/Debian Default)
Edit ~/.bashrc instead of .zshrc using the same syntax:
export PATH=$PATH:/custom/bin/pathStep 3: Configure PATH on Windows
On Windows, you must add the folder containing your .exe file to the User or System Environment Variables.
Method A: Using the Graphical Interface (GUI)
- Press the Windows Key and type "environment variables". Select "Edit the system environment variables".
- Click the "Environment Variables..." button at the bottom.
- Under "User variables" (or System variables), find the variable named "Path" and select it, then click "Edit...".
- Click "New" and paste the folder path (e.g.,
C:\Program Files\Nodejs\). - Click "OK" to close all windows.
- Crucial: Close your open terminal windows (VS Code terminal, Command Prompt, or PowerShell) and launch a new terminal session for the updated environment variables to take effect.
Method B: Using PowerShell
To append a path folder permanently using PowerShell (run as Administrator):
$CurrentPath = [Environment]::GetEnvironmentVariable("Path", "User")
[Environment]::SetEnvironmentVariable("Path", $CurrentPath + ";C:\custom\bin\path", "User")Conclusion
The "command not found" error means your shell cannot locate a program binary within the folders declared in its PATH variable list. By verifying the program installation directory, appending the target directory path to .zshrc or .bashrc profiles on macOS/Linux, or updating the environment variables table on Windows, you can resolve CLI access issues.