Fix "command not found" and "is not recognized as an internal or external command"
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
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.
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
- 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.
- Folder missing from PATH:
~/.local/bin,~/.cargo/bin,/opt/homebrew/binon Apple Silicon Macs,%AppData%\npmor Python'sScriptsfolder on Windows. - Terminal opened before the install: a terminal reads
PATHwhen it starts. On Windows, VS Code and already open terminals keep the old value. - PATH edited in the wrong file or overwritten: zsh (the macOS default) reads
~/.zshrcand~/.zprofile, not~/.bash_profile; anexport PATH=/my/folderwithout$PATHwipes everything else. - Typo or different name:
pythoninstead ofpython3on macOS and Linux, different case, or an alias defined only in another shell.
Step-by-step fix
-
Check whether the command exists
Ask the shell where it finds the command and print the contents of
PATH, one folder per line.# macOS / Linux command -v npm type -a npm echo $PATH | tr ':' '\n' -
Do the same on Windows
In PowerShell,
Get-Commandlooks up the command and$env:Pathholds the folder list separated by semicolons. In cmd, usewhere npm.Get-Command npm where.exe npm $env:Path -split ';' -
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.# macOS (Homebrew) brew install node # Debian / Ubuntu sudo apt install nodejs npm # Windows (PowerShell) winget install OpenJS.NodeJS.LTS -
Add the folder to PATH (macOS / Linux)
Prepend the folder to
PATHwhile keeping the old value, in~/.zshrcfor zsh or~/.bashrcfor bash, then reload the file. On Apple Silicon Macs, Homebrew lives in/opt/homebrewand must be initialized in~/.zprofile.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)" -
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.$userPath = [Environment]::GetEnvironmentVariable('Path', 'User') [Environment]::SetEnvironmentVariable('Path', "$userPath;C:\Tools\bin", 'User') -
Open a new terminal
Close and reopen the terminal so it reads
PATHagain. In VS Code, quit the whole application, not just the terminal tab. If the shell caches an old location, clear the cache withhash -r(bash) orrehash(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
PATHfor you. - When you edit
PATH, always append:$PATH(or;on Windows) so you do not overwrite the existing value. - Keep your
PATHedits 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
- Fix "running scripts is disabled on this system" in PowerShell
- Fix "xcrun: error: invalid active developer path" on macOS
- Fix "SSL certificate problem: unable to get local issuer certificate" (git, curl, pip, npm)
- Fix "user is not in the sudoers file. This incident will be reported."
- Fix "/bin/bash^M: bad interpreter: No such file or directory"
- Fix "E: Could not get lock /var/lib/dpkg/lock-frontend" (apt, Ubuntu, Debian)
- Fix "App is damaged and can't be opened" on macOS (Gatekeeper)