command not found after installation on Linux/macOS: diagnose the cause, locate the executable, and fix PATH correctly

    This article explains why a successfully installed CLI may still produce "command not found" on Linux or macOS. It shows how to interpret the error, use location commands to find where the executable actually resides, and apply targeted fixes based on the installation method. It includes a directory comparison table, examples for temporary and permanent PATH changes, guidance for cleaning up multiple installations, and a practical verification checklist.

    Introduction: installed successfully does not mean directly callable

    Many developers encounter their first obstacle with an AI coding tool as a simple terminal error. They type the command name, but the screen only returns “command not found.” The answers they find online are often almost identical: append a line to the shell configuration file to add a user-level bin directory to PATH.

    After following that advice, some users solve the problem, while others see no change at all, or even make the configuration more complicated. The root cause is that the suggested command assumes the tool was installed into a specific directory, and this is only one possible installation location among several. The correct way to solve this problem is not to modify the configuration first, but to first confirm where the executable file actually is.

    1. What “command not found” really means

    The error message itself contains several clues:

    • macOS/Linux: <cli>: command not found or zsh: command not found: <cli>
    • Windows Command Prompt: the command is not recognized as an internal or external command, operable program, or batch file.

    These messages all indicate the same thing: the current shell searched its defined search paths and did not find an executable file named xxx. There are two easily overlooked details here.

    First, the shell does not scan the entire disk. It only searches the directories registered in the PATH variable. On Unix-like systems, PATH is a list of directories separated by colons. On Windows, the separator is a semicolon, and environment variables are divided into user-level and system-level categories.

    Second, shells on Linux and macOS cache the mapping between commands and paths, also known as hashing. If the same command name was typed before the installation and triggered an error, that name may have been marked as “not found” and cached. Even after the tool is installed and PATH is updated, the current session may still use the old result.

    2. Why blindly appending to PATH often does not work

    “Add the user directory to PATH” is essentially a rule of thumb. It only works when the installation method uses the corresponding default path. Here are common reasons it fails.

    2.1 The installation method determines the actual file location

    Even if a tool is “installed,” the executable may be placed in completely different directories:

    Installation method Typical executable location
    Official installation script, default behavior ~/.local/bin/<cli>
    System-level package manager /usr/local/bin/<cli>, /opt/<vendor>/bin/<cli>, etc.
    Global package manager installation The package manager’s global bin directory, which may vary with the runtime version or current project
    GUI installer The application directory, often with a symbolic link to /usr/local/bin
    Windows command-line installer User directories such as %LOCALAPPDATA%\Programs\<vendor>\<cli>

    Only the first type of tool is placed in ~/.local/bin by default. If you installed the tool with a package manager, the executable is likely already in a directory known to the system. Adding ~/.local/bin to PATH in that case will not improve anything.

    2.2 The configuration was written to the wrong file or was not reloaded

    Linux and macOS have multiple shell configuration entry points, each with a different role:

    • ~/.bashrc: read by interactive shells;
    • ~/.bash_profile: read by login shells;
    • ~/.zshrc: read by interactive zsh sessions;
    • ~/.zprofile: read by login zsh sessions.

    A change only takes effect if it is written to the file actually read by the current session and the file is reloaded in that session. You can reload it with source <file> or by opening a new terminal.

    2.3 Environment variable changes on Windows do not take effect immediately

    On Windows, a running terminal process reads environment variables when it starts. After you modify system or user variables, already-open terminal windows, IDE terminals, and even the IDE itself may not detect the change. You must restart the relevant processes.

    In addition, system variables written with administrator privileges are not automatically synchronized to GUI programs running with normal user privileges. You also need to pay attention to variable order. A newly added directory is usually appended to the end of PATH, giving it lower priority than directories that appear earlier. As a result, an older version of a command with the same name may still be found first.

    2.4 The file was not actually generated

    Some installation commands exit early when a step fails, for example because of a interrupted download, insufficient permissions, or missing dependencies. If the return code is not checked, users may assume the installation completed successfully, but the target file may not exist on disk at all.

    3. First fix step: locate the file instead of changing PATH first

    3.1 Run a location command as a quick diagnosis

    1. # Linux / macOS: list all matching commands found in the current PATH
    2. which -a <cli>
    1. REM Windows: query the tool location and list multiple candidates with the same name
    2. where <cli>

    The result is usually one of three situations:

    1. A path is printed: this means the current PATH can already find the command. If the error still appears, it is likely a caching issue or a multiple-installation issue. You can go directly to sections 4 and 5.
    2. No output is printed: the command is indeed not in PATH. Continue to the next step and distinguish between “installed but the directory is not in PATH” and “not installed at all.”
    3. Multiple paths are printed: multiple installations exist, and cleanup is needed.

    3.2 If there is no result, check common candidate directories one by one

    Use directory listing commands to confirm whether the file actually exists in common installation locations:

    1. ls -la ~/.local/bin/<cli> # default location for official installation scripts
    2. ls -la /usr/local/bin/<cli> # system-level package manager installation
    3. ls -la /opt/*/bin/<cli> # installation location for some third-party package managers

    For tools installed globally through a package manager, the location is usually determined by that manager’s global bin directory. Runtime version managers may change this directory by modifying PATH for the current project. Therefore, the installation and launch commands should be executed in the same project.

    The directory returned by the command that lists the file is the target directory that should be added to PATH. If none of the commands produce output, the installation itself did not complete. You should rerun the installation and pay attention to the return code and output messages.

    4. Fix the issue based on the location result

    4.1 A file exists, but its directory is not in PATH: complete PATH

    Linux / macOS: temporary effect for the current session

    1. export PATH="<actual directory>:$PATH"

    Linux / macOS: permanent effect

    1. # Write the actual directory into your shell configuration file and append one line
    2. echo 'export PATH="<actual directory>:$PATH"' >> ~/.zshrc # or ~/.bashrc
    3. source ~/.zshrc

    Two details are worth noting:

    • Wrap the directory in double quotes so that paths containing spaces are handled correctly.
    • Place the newly added directory before $PATH so that it can take priority over older versions.

    Windows

    Open “Settings → System → System information → Advanced system settings → Environment Variables.” In “User variables,” edit Path, create a new entry pointing to the actual directory, and save. Then close all terminals and reopen them. IDEs and logged-in desktop sessions usually need a logout or restart before they can detect the change.

    4.2 Multiple installations: keep one and remove the rest

    When which -a returns multiple results, first check the version of each one:

    1. <cli> --version
    2. "<another directory>/<cli>" --version

    If you need an older version, the safest approach is to uninstall the copies you do not use. This can be done through the corresponding package manager, or by deleting files generated by the installation script. Then confirm the return value of the installation command:

    1. <install command>; echo "exit code: $?"

    If you only need a temporary switch, you can add a line before the startup script so that the current project uses a specific version:

    1. #!/bin/bash
    2. export PATH="<target directory>:$PATH"
    3. exec <cli> "$@"

    5. Other common but easily overlooked causes

    • The file exists but cannot be executed: Linux and macOS report Permission denied, which usually means the executable permission is missing. You can try chmod +x <path>. However, if the program is located in a directory where only root can write, the more fundamental problem is that the user does not have permission to execute it. In that case, prefer a user-level installation.
    • The interpreter declared by the script is missing: if a script starting with #! declares an interpreter that does not exist, it reports bad interpreter. You need to install the corresponding runtime environment.
    • It can be launched from the GUI menu but fails in the terminal: GUI environments and terminals use different search mechanisms. A GUI menu launching successfully does not mean the command is available in the command line.
    • PowerShell execution policy restrictions: on Windows, if the script being called ends with .ps1, the default execution policy may block it. This is a policy configuration issue, not a path issue.

    6. Troubleshooting checklist

    1. Run which -a or where to confirm whether the command is already in the current PATH.
    2. Use directory listing commands to confirm the real location of the file.
    3. Confirm that the configuration file matches the shell type and has been sourced or that a new terminal has been opened.
    4. Confirm whether the PATH change takes effect for the current process. On Windows, restart the relevant processes.
    5. Check whether multiple installations or version conflicts exist.
    6. Confirm that the installation command returned exit code 0.
    7. If the file exists but cannot be executed, check permissions, architecture, and dependencies.
    8. After handling the above issues, run <cli> --version again as the final verification.

    7. Preventive habits: make “ready to use after installation” the default

    The troubleshooting process above is essentially “discover first, fix second.” To reduce these problems, you can develop four habits before and after installation:

    • Check the current state first: run which -a once before installation to understand the current environment.
    • Keep a consistent location: prefer user-level installation methods that do not depend on extra runtimes, and reduce the chance of multiple commands with the same name.
    • Verify immediately: after installation, immediately run which -a and --version instead of waiting for an error to appear.
    • Use an explicit entry point: fix PATH in startup scripts or aliases to reduce uncertainty caused by environment drift.

    This “locate first, then fix” method is not limited to a particular tool. Any “command not found after installation” problem is essentially a mismatch between the shell’s search scope and the target file’s location. Locating the file is a prerequisite for fixing the issue. Even when using cloud hosts or cloud development environments on cloud platforms, this troubleshooting logic still applies: login methods, shell startup scripts, and the way PATH is assembled may differ slightly, but the principle of “first confirm where the file is, then decide what to change” remains the same.