Skip to content
FR
  1. LuzineDebug
  2. Systems (Windows, macOS, Linux)
  3. zsh: command not found: npm
Systems (Windows, macOS, Linux) Beginner ≈ 5 min to fix

Fix "command not found" and "is not recognized as an internal or external command"

Error message
zsh: command not found: npm
  • bash: npm: command not found
  • 'npm' is not recognized as an internal or external command, operable program or batch file.
  • npm : The term 'npm' is not recognized as the name of a cmdlet, function, script file, or operable program.
  • sh: 1: npm: not found
  • fish: Unknown command: npm
In short

The shell cannot find any executable with that name in the folders listed in the PATH variable. Either the program is not installed, its folder is not in PATH, or the terminal was opened before the install. Check with which or where, add the right folder to PATH, then open a new terminal.

Be the first to confirm this fix

What this error means

When you type a command, the shell (zsh, bash, cmd, PowerShell) looks for an executable file with that name in each folder of the PATH environment variable, in order. If it finds none and the name is not an alias, function or built-in, it prints "command not found" on macOS and Linux, or "is not recognized as an internal or external command" on Windows. The program may well exist on disk: it is just in a folder the shell does not look in.

Common causes

  1. Program not installed in this environment: another Node version via nvm, Python virtual environment not activated, install done by another user or inside a container.
  2. Folder missing from PATH: ~/.local/bin, ~/.cargo/bin, /opt/homebrew/bin on Apple Silicon Macs, %AppData%\npm or Python's Scripts folder on Windows.
  3. Terminal opened before the install: a terminal reads PATH when it starts. On Windows, VS Code and already open terminals keep the old value.
  4. PATH edited in the wrong file or overwritten: zsh (the macOS default) reads ~/.zshrc and ~/.zprofile, not ~/.bash_profile; an export PATH=/my/folder without $PATH wipes everything else.
  5. Typo or different name: python instead of python3 on macOS and Linux, different case, or an alias defined only in another shell.

Step-by-step fix

  1. Check whether the command exists

    Ask the shell where it finds the command and print the contents of PATH, one folder per line.

    bash
    # macOS / Linux
    command -v npm
    type -a npm
    echo $PATH | tr ':' '\n'
  2. Do the same on Windows

    In PowerShell, Get-Command looks up the command and $env:Path holds the folder list separated by semicolons. In cmd, use where npm.

    powershell
    Get-Command npm
    where.exe npm
    $env:Path -split ';'
  3. Install the program if it is missing

    Prefer your system's package manager: it puts the executable in a folder that is already in PATH.

    bash
    # macOS (Homebrew)
    brew install node
    # Debian / Ubuntu
    sudo apt install nodejs npm
    # Windows (PowerShell)
    winget install OpenJS.NodeJS.LTS
  4. Add the folder to PATH (macOS / Linux)

    Prepend the folder to PATH while keeping the old value, in ~/.zshrc for zsh or ~/.bashrc for bash, then reload the file. On Apple Silicon Macs, Homebrew lives in /opt/homebrew and must be initialized in ~/.zprofile.

    bash
    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc
    
    # Homebrew on Apple Silicon
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
  5. Add the folder to PATH (Windows)

    Use "Edit environment variables for your account" > Path > New, or PowerShell. Do not use setx PATH "%PATH%;...": it truncates the value to 1024 characters and copies the system PATH into the user PATH.

    powershell
    $userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
    [Environment]::SetEnvironmentVariable('Path', "$userPath;C:\Tools\bin", 'User')
  6. Open a new terminal

    Close and reopen the terminal so it reads PATH again. In VS Code, quit the whole application, not just the terminal tab. If the shell caches an old location, clear the cache with hash -r (bash) or rehash (zsh).

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Install your tools with a package manager (Homebrew, apt, winget) that handles PATH for you.
  • When you edit PATH, always append :$PATH (or ; on Windows) so you do not overwrite the existing value.
  • Keep your PATH edits in a single config file per shell so you know where to look.

Frequently asked questions

Why does the command work in one terminal but not in VS Code?

VS Code inherits the environment from when it was launched. If you installed the tool or changed PATH afterwards, fully quit VS Code and start it again.

What is the difference between .zshrc and .zprofile?

~/.zprofile is read by login shells, ~/.zshrc by every interactive shell. On macOS, putting PATH in either works in Terminal; Homebrew recommends ~/.zprofile.

Why "python: command not found" on macOS?

macOS no longer ships a python command, only python3. Use python3 and python3 -m pip, or activate a virtual environment that provides python.

Useful tools for this error

More Systems (Windows, macOS, Linux) errors

All Systems (Windows, macOS, Linux) errors →