Command Not Found in Terminal: A Troubleshooting Guide for Installing AI Coding Tools
This guide explains why a terminal returns "command not found" when launching an AI coding tool and walks through a structured fix: understand how the shell resolves commands via PATH, identify where your installation method actually placed the executable, locate the binary, repair the configuration, and verify it in the current session. It also covers resolving conflicts from multiple installations and common cross-platform pitfalls, so you can diagnose most installation failures in minutes.
Introduction: What a One-Line Error Really Means
You type the launch command for an AI coding tool in your terminal and get only “not recognized as an internal or external command” or “command not found.” Almost everyone configuring a command-line development environment for the first time runs into this. The first instinct in most online tutorials is to immediately edit the environment variables and append some directory to PATH. That only works for certain installation methods, does nothing for others, and can leave an already clear environment even more tangled.
To actually solve the problem, you need to understand the nature of the error first, then proceed in the order locate, diagnose, fix, verify, rather than blindly copying commands.
1. The Root Cause: How the Shell Looks Up Commands
When the shell executes a command, it does not scan the whole machine. It only searches the directories listed in the PATH environment variable, in order, for an executable with the same name. If none of those directories match, it throws command not found.
Two key conclusions follow:
- The program exists, but its directory is not registered in PATH, so it reports not found.
- The program was never installed successfully, which also reports not found.
These two cases require completely different handling, so the first step is never to change configuration, but to locate.
You can use the following illustrative commands to inspect the current PATH:
echo "$PATH" # Unix-like systemsecho %PATH% # Windows Command Prompt$env:Path # Windows PowerShell
2. Your Installation Method Determines Where Files Land
Command-line AI coding tools are typically installed through three channels, and each puts the executable in a different place:
| Installation channel | Typical location |
|---|---|
| Official script installer | A local bin directory under the user home |
| System-level package manager | The bin directory maintained by the package manager; the path differs by chip architecture |
| Language runtime global install | The global bin directory of the runtime environment, which changes as versions switch |
Key takeaway: only the official script installation writes to a user-level local directory by default. If you used a system package manager or a runtime global install but added the user local directory to PATH, that is just an empty directory, so the error persists.
3. The First Step Is Always to Locate, Not to Change Configuration
Regardless of your operating system, start with an existence check that lists all matches:
which -a claude # Unix-like; list all matching executables in PATHwhere claude # Windows Command PromptGet-Command claude # PowerShell
The output falls into three cases.
Case 1: A path is printed
It is already in PATH and usable. If you still get not found, it is usually because multiple versions are installed and competing, or the current terminal session has stale environment variables. Move on to the multiple-installation flow.
Case 2: No output at all
It genuinely cannot be found in PATH. Check the common locations one by one for the file:
ls -l ~/.local/bin/claudels -l /opt/homebrew/bin/claudels -l /usr/local/bin/claudenpm -g ls @anthropic-ai/claude-code
Whichever command prints a file, that directory is the target to add to PATH. If all are empty, the installation step itself failed; go back and redo it, and watch the install log for permission and network errors.
Case 3: Multiple paths are printed
This is a multiple-installation conflict; see Section 5.
4. Fix and Verify: Make the Configuration Take Effect in the Current Session
Once you have confirmed the target directory, write it into your shell configuration file. On Unix-like systems, distinguish the shell type in use and append to the matching file:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrcsource ~/.zshrc
On Windows, the recommended approach is to add an entry through the Environment Variables GUI in System Properties, or to set it temporarily in PowerShell and then verify:
$env:Path += ";C:\Users\me\.local\bin"
Verification has two layers: first use the existence check to confirm the path now resolves, then run the command once with a version flag to confirm the program actually starts rather than merely being found. After editing the configuration file you must reload it or open a new terminal; the old session will not inherit the change automatically.
5. Multiple-Installation Conflicts: Why It “Works” but Behaves Oddly
When a package manager, a script installer, and a runtime global install all exist at once, the earlier directory in PATH overrides the later one, producing strange behavior such as version rollbacks and updates that never take effect. The principle is to keep only one installation channel:
which -a claude # find every copynpm -g uninstall ... # remove the extra copieshash -r # clear the shell command path cache
After uninstalling, always clear the cache, otherwise the shell will keep remembering the deleted path.
6. Platform Differences and Common Pitfalls
- Unix-like systems are case-sensitive while Windows is not, so cross-platform scripts should not rely on case assumptions.
- Permission problems are often mistaken for “not installed”; a missing executable bit makes the program impossible to invoke as well.
- Temporary variables injected into a session are lost after a restart and must be written into the configuration file.
- In enterprise environments using container platforms or cloud development environments, the path layout inside the image may differ from local, so rely on the actual query results inside the image, and use log services and monitoring alerts to pinpoint problems at the build stage.
Conclusion
“Command not found” is never magic; it is a matter of paths and lookup rules. Stick to the order locate, diagnose, then modify, combined with minimal verification steps, and the vast majority of installation failures converge within minutes. Turn this troubleshooting flow into a personal environment-configuration standard, and you can reuse it for any command-line tool you add later.
