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/bin or ~/bin), and that directory is often not in PATH by 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):

    1. which -a claude

    Or in Windows CMD / PowerShell:

    1. Get-Command claude -ErrorAction SilentlyContinue

    Interpreting the result:

    • Case A: a path is printed (for example /opt/homebrew/bin/claude)
      The tool is already in PATH and 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 run hash -r to 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:
    1. ls -la ~/.local/bin/claude # default location of the official native installer
    2. ls -la /opt/homebrew/bin/claude # package manager location (ARM architecture)
    3. ls -la /usr/local/bin/claude # package manager location (Intel architecture)
    4. 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.

    1. Identify your shell type:
      Most modern Linux and macOS systems default to zsh or bash. Check with echo $SHELL.

    2. Edit the configuration file:

      • For zsh, edit ~/.zshrc.
      • For bash, edit ~/.bashrc or ~/.bash_profile.
    3. Add the configuration line:
      Assuming the path to add is ~/.local/bin, append the following to the end of the file:

      1. # Prepend the user's custom bin directory to PATH
      2. export PATH="$HOME/.local/bin:$PATH"

      Or, if you installed through a package manager and the path is /usr/local/bin (usually already in PATH; add it if not):

      1. export PATH="/usr/local/bin:$PATH"
    4. Apply the configuration:
      Run source to make the change take effect immediately, with no reboot required:

      1. source ~/.zshrc

    Step 3: Windows-Specific Handling

    If you use the native Windows terminal (CMD / PowerShell), the approach differs slightly:

    1. Modify the system environment variable:
      Right-click “This PC” -> “Properties” -> “Advanced system settings” -> “Environment Variables”. Find Path under “User variables” or “System variables”, click “Edit”, and add the folder containing claude.exe (for example C:\Users\YourName\.local\bin).

    2. Adjust the PowerShell execution policy:
      If running a script in PowerShell fails with a “scripts are disabled” error, open PowerShell as administrator and run:

      1. Set-ExecutionPolicy RemoteSigned

      Type Y to 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 claude prints both /usr/bin/claude and /usr/local/bin/claude.
    • Fix: Check the order of the PATH variable; directories listed earlier take priority. Delete or rename the unused older files, or use a package manager (npm uninstall -g or brew 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:

    1. 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.

    2. 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.

    3. Understand “global” versus “local” installation: When installing tools with npm or pip, be clear about what the -g (global) flag means. Globally installed packages usually live in system-level directories and may require sudo privileges; local installations live in the project’s node_modules or .venv directory and must be invoked via a relative path (such as npx 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“:

    1. Confirm the file actually exists.
    2. Confirm the shell recognizes the directory containing the file.
    3. Confirm the execute permissions are sufficient.

    Once these three layers are clear, the vast majority of CLI tool installation and configuration problems are resolved.