Command Not Found: Troubleshooting and Fixing CLI Tool Download Errors
This guide explains why terminal commands such as `command not found` or `Permission denied` occur after installing CLI tools, and walks through a step-by-step workflow to locate the executable, configure the PATH environment variable on Linux, macOS, and Windows, adjust the PowerShell execution policy, and resolve multiple installations or version conflicts. It also covers best practices for avoiding these issues in the future.
Command Not Found: Troubleshooting and Fixing CLI Tool Download Errors
When developing on Windows (CMD / PowerShell / WSL) or Unix-like systems (Linux / macOS), installing AI coding assistants or command-line developer tools through the terminal has become the mainstream approach. However, many developers run the official curl or npm installation commands, try to launch the program, and repeatedly hit errors such as command not found, 'claude' is not recognized as an internal or external command, or script execution failures.
These problems are usually not caused by a broken system. They come from an unconfigured environment path, a faulty installation source, or permission policy restrictions. This article breaks down the underlying causes of CLI tool download and launch errors, and provides a rigorous process for diagnosing and fixing them.
1. Why the Terminal Cannot Find the Command
When you type a command into the shell and press Enter, the shell does not scan the entire disk. It searches for the matching executable according to specific rules. The errors generally fall into three categories.
1.1 The Executable’s Directory Is Not in PATH
After receiving a command, the shell looks in the current directory first, then searches each path listed in the PATH environment variable in order. If the directory containing the tool’s executable is not in PATH, the shell treats the command as nonexistent.
- Common scenario: Tools installed with an official native installer land in a hidden folder under the user’s home directory (such as
~/.local/binor~/bin), and that directory is often not inPATHby default.
1.2 Multiple Versions or a Failed Installation
Sometimes command not found does not mean the file is missing entirely. The installation may have failed silently, or multiple versions of the executable may exist, leaving the shell with cached path information from an older version.
- Common scenario: When installing through a package manager (Homebrew, Choco, NPM), a network interruption can leave the download half-finished; or an older version of the tool was installed previously and the new version did not overwrite it cleanly.
1.3 Download and Execute Permission Issues
On Unix-like systems, running a downloaded file without the execute permission produces Permission denied. On Windows PowerShell, if the default execution policy is Restricted, no script file (such as a .ps1 installer) is allowed to run.
2. Step-by-Step Troubleshooting and Fixes
The following standardized workflow moves from locating the problem to fixing it.
Step 1: Find Where the Tool Was Actually Installed
Blindly editing PATH is the most common mistake beginners make. If the tool is installed in /usr/local/bin but you configure ~/.local/bin, you will not fix the problem and will only make the environment more confusing.
Commands to run:
In the terminal, search for every executable named claude (the tool name in this example):
which -a claude
Or in Windows CMD / PowerShell:
Get-Command claude -ErrorAction SilentlyContinue
Interpreting the result:
- Case A: a path is printed (for example
/opt/homebrew/bin/claude)
The tool is already inPATHand should work. If you still get an error, the current terminal session may not have refreshed, or an alias may be conflicting. Close the terminal and reopen it, or runhash -rto clear the shell’s command path cache. - Case B: nothing is printed
The shell genuinely cannot find the file. Confirm whether the file exists on disk by checking these common locations in order:
ls -la ~/.local/bin/claude # default location of the official native installerls -la /opt/homebrew/bin/claude # package manager location (ARM architecture)ls -la /usr/local/bin/claude # package manager location (Intel architecture)npm list -g @anthropic-ai/claude-code # check whether the global module installed successfully
Whichever command returns file information points to the directory you need to add to PATH.
Step 2: Configure the Environment Variable (Linux / macOS)
Once the path is confirmed, add it permanently to the shell’s startup configuration file.
Identify your shell type:
Most modern Linux and macOS systems default tozshorbash. Check withecho $SHELL.Edit the configuration file:
- For zsh, edit
~/.zshrc. - For bash, edit
~/.bashrcor~/.bash_profile.
- For zsh, edit
Add the configuration line:
Assuming the path to add is~/.local/bin, append the following to the end of the file:# Prepend the user's custom bin directory to PATHexport PATH="$HOME/.local/bin:$PATH"
Or, if you installed through a package manager and the path is
/usr/local/bin(usually already inPATH; add it if not):export PATH="/usr/local/bin:$PATH"
Apply the configuration:
Runsourceto make the change take effect immediately, with no reboot required:source ~/.zshrc
Step 3: Windows-Specific Handling
If you use the native Windows terminal (CMD / PowerShell), the approach differs slightly:
Modify the system environment variable:
Right-click “This PC” -> “Properties” -> “Advanced system settings” -> “Environment Variables”. FindPathunder “User variables” or “System variables”, click “Edit”, and add the folder containingclaude.exe(for exampleC:\Users\YourName\.local\bin).Adjust the PowerShell execution policy:
If running a script in PowerShell fails with a “scripts are disabled” error, open PowerShell as administrator and run:Set-ExecutionPolicy RemoteSigned
Type
Yto confirm. This policy allows locally created scripts to run while requiring scripts downloaded from the internet to be signed, balancing security and convenience.
Step 4: Handle Multiple Installations and Version Conflicts
If which claude returns multiple paths, or errors appear after an upgrade, multiple versions exist on the system.
- Symptom:
which -a claudeprints both/usr/bin/claudeand/usr/local/bin/claude. - Fix: Check the order of the
PATHvariable; directories listed earlier take priority. Delete or rename the unused older files, or use a package manager (npm uninstall -gorbrew uninstall) to remove the redundant versions completely and keep the environment clean.
3. Advanced Recommendations and Best Practices
To avoid running into these problems again, follow these development conventions:
Use a cloud development environment: If you frequently cannot reach the official download source from your local network (causing download errors or timeouts), consider a cloud development environment such as Baidu AI Cloud’s cloud servers (BCC) or Function Compute (CFC). Cloud environments typically ship with well-configured language runtimes (such as Node.js and Python) and more stable network egress, which greatly reduces installation failures caused by network conditions.
Use containerization: For complex AI coding tool dependencies, container technology such as Docker is recommended. Packaging the tool and its dependencies into an image avoids polluting the host machine’s environment variables and solves the classic “it runs on my machine but fails on yours” problem.
Understand “global” versus “local” installation: When installing tools with
npmorpip, be clear about what the-g(global) flag means. Globally installed packages usually live in system-level directories and may requiresudoprivileges; local installations live in the project’snode_modulesor.venvdirectory and must be invoked via a relative path (such asnpx tool-name).
Summary
When you hit command not found or a download error, follow the principle of “locate first, configure second, then check permissions and conflicts“:
- Confirm the file actually exists.
- Confirm the shell recognizes the directory containing the file.
- Confirm the execute permissions are sufficient.
Once these three layers are clear, the vast majority of CLI tool installation and configuration problems are resolved.
