Troubleshooting

npx: command not found? Fix it on Linux, macOS and Windows

npx comes with npm and Node.js: install Node.js LTS and open a new terminal. Exact fixes for zsh on macOS, bash, sudo, Docker, MCP apps and Windows cmd.

Published · Updated ~11 min read
On this page

Short answer: npx is part of npm, and npm comes with Node.js. There is no separate npx to install. So zsh: command not found: npx, bash: npx: command not found and Windows’ 'npx' is not recognized as an internal or external command, all mean the same thing: Node.js is not installed, or it is installed somewhere this shell does not look. Install the current LTS release of Node.js, open a new terminal, and check:

any system
node --version
npm --version
npx --version
  • macOS: brew install node, or the installer from nodejs.org. Details, including zsh: command not found: brew, are below.
  • Debian and Ubuntu: Node.js from NodeSource. apt install nodejs on its own gives you node without npm or npx (commands).
  • Windows: winget install OpenJS.NodeJS.LTS, then close every terminal and editor window and open them again (details).

Node is installed and npx still fails? Then the problem is the PATH of that one shell, of sudo, of an app or of a container. Find your exact message in the table.

Which error do you see?

MessageWhere it appearsCause and fix
zsh: command not found: npxmacOS Terminal (zsh is the default shell), zsh on LinuxNode missing, or zsh does not load Homebrew or nvm: zsh, macOS
bash: npx: command not foundLinux terminalNode missing (install), or node without npm (node works, npx does not)
-bash: npx: command not foundSSH login shellThe same, or a login file that does not load nvm (nvm)
sh: 1: npx: not found or /bin/sh: 1: npx: not foundDockerfile RUN, cron, scripts run with sh on Debian or Ubuntu (dash)That environment has no Node on its PATH: Docker, cron
/bin/sh: npx: not foundAlpine image (BusyBox sh)No Node in the image: Docker
sudo: npx: command not found or sudo: 'npx': command not foundsudo; the quoted form is sudo-rs (Ubuntu 25.10, 26.04)sudo uses its own PATH: sudo
/usr/bin/env: ‘node’: No such file or directory (straight quotes in a C locale)npx called by its full path (sudo, cron, services)npx was found, node was not: sudo
'npx' is not recognized as an internal or external command,Windows cmdWindows
npx : The term 'npx' is not recognized as the name of a cmdlet (5.1) or npx: The term 'npx' is not recognized as a name of a cmdlet (7)Windows PowerShell 5.1, PowerShell 7Windows
npx.ps1 cannot be loaded because running scripts is disabled on this systemPowerShellExecution policy, not PATH: PowerShell
spawn npx ENOENT or exec: "npx": executable file not found in $PATHEditors, AI apps, MCP serversThe app does not get your shell’s PATH: apps
.husky/pre-commit: 1: npx: not found and husky - command not found in PATH=…git commit from VS Code or a GUI git clientThe hook gets the app’s PATH: git hooks

Find the cause in one minute

bash · zsh
command -v node npm npx       # the path of each one this shell finds
echo "$PATH" | tr ':' '\n'     # the directories it searches
  • No path for node: Node.js is not installed, or not on this PATH. Install it.
  • A path for node, none for npm and npx: a distribution package without npm. See node works, npx does not.
  • All three found here, but npx fails elsewhere (a new terminal, sudo, cron, an app, a container): that environment has its own PATH; the table names the section.

Install Node.js (npm and npx included)

Debian and Ubuntu: NodeSource

This installs the current LTS release system-wide, with npm and npx, into /usr/bin. That directory is on every PATH, sudo’s included, which is what you want on a server where services and cron jobs run as other users.

Debian · Ubuntu
sudo apt update && sudo apt install -y ca-certificates curl
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs

Any Linux or macOS: nvm

nvm installs Node into your home directory and switches versions per project: good on a development machine, wrong for a service account, because only shells that load nvm see that Node.

Linux · macOS
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bash

Close the terminal, open a new one, then:

bash · zsh
nvm install --lts

nvm: command not found in the new terminal means the installer wrote its lines to a file your shell does not read (fix).

macOS: Homebrew or the installer

macOS does not include Node.js. The installer package from nodejs.org puts node, npm and npx into /usr/local/bin, which macOS searches by default. With Homebrew it is one command, which installs the newest Node release. For a fixed major version, use a versioned formula such as node@24 (below):

macOS · Homebrew
brew install node

If zsh also says zsh: command not found: brew, Homebrew’s directory is not on your PATH. On Apple Silicon it is /opt/homebrew, which macOS does not search; the Homebrew installer ends by printing the lines for ~/.zprofile. If you skipped them, add this one and open a new terminal:

~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

Versioned formulae such as node@24 are keg-only: Homebrew installs them but does not link them into /opt/homebrew/bin, so npx stays “not found” after brew install node@24. Put its own bin directory first:

~/.zshrc
export PATH="/opt/homebrew/opt/node@24/bin:$PATH"

On an Intel Mac, an existing Homebrew keeps working from /usr/local instead of /opt/homebrew. A new Homebrew install there stops with Homebrew on macOS is only supported on Apple Silicon processors!, so use the installer package from nodejs.org instead.

Alpine and RHEL family

Alpine
apk add --no-cache nodejs npm
Rocky · AlmaLinux 9.7 or later
sudo dnf module enable -y nodejs:24
sudo dnf install -y nodejs npm
Rocky · AlmaLinux 10
sudo dnf install -y nodejs nodejs-npm

“zsh: command not found: npx” after installing Node

This is the most common variant, and it is not a zsh bug. zsh reads ~/.zshrc for interactive shells and ~/.zprofile for login shells, which is what macOS Terminal opens. It never reads ~/.bashrc, ~/.bash_profile or ~/.profile. Installers that put their PATH lines into one of those leave zsh blind:

  • nvm picks the file from your $SHELL and from the files that already exist. Under zsh it uses ~/.zshrc or ~/.zprofile, but only if one of them exists. A new Mac has neither, so the installer falls back to ~/.profile, ~/.bashrc or ~/.bash_profile, or prints => Profile not found and writes nothing.
  • Homebrew needs its shellenv line in ~/.zprofile, as shown above.

For nvm, add its three lines to ~/.zshrc:

~/.zshrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Open a new terminal and run command -v npx: it should print a path under ~/.nvm/versions/node/. After installing something while zsh is open, rehash refreshes its list of commands.

It works in one terminal, not in a new one

nvm puts Node on the PATH of each shell separately. A new shell starts with the version named by the default alias. The first version you install becomes the default, but if you later removed it, new shells start without Node, and so without npx.

bash · zsh
nvm ls
nvm alias default node

node means the newest version installed; nvm alias default 24 pins a major version instead. Over SSH, bash starts as a login shell and reads ~/.bash_profile or, if that does not exist, ~/.profile, not ~/.bashrc where nvm wrote its lines. Debian and Ubuntu’s stock ~/.profile loads ~/.bashrc. A ~/.bash_profile you created yourself does not, which is where -bash: npx: command not found comes from. Add [ -f ~/.bashrc ] && . ~/.bashrc to it.

“sudo: npx: command not found”

Here npx exists for your user and not for the command sudo runs. On Linux, sudo replaces your PATH with secure_path from /etc/sudoers, which on Debian 12 is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. A Node under ~/.nvm, or in any other directory you added to PATH yourself, is not on it. Classic sudo says sudo: npx: command not found. sudo-rs, the default sudo on Ubuntu 25.10 and 26.04, says sudo: 'npx': command not found.

Giving sudo the full path is not enough. npx starts with #!/usr/bin/env node, so it then fails with /usr/bin/env: ‘node’: No such file or directory (with straight quotes when no UTF-8 locale is set). Pass your PATH along for that one command:

bash · zsh
sudo env "PATH=$PATH" npx COMMAND

Your shell expands $PATH before sudo starts, so root gets your directories for this one command. That is a stopgap: for anything that runs as root regularly, install Node system-wide with NodeSource so npx is in /usr/bin. Better still, do not run npm packages as root at all; their install scripts get whatever rights you give them.

In Docker, CI, cron and systemd

Dockerfile RUN lines and cron jobs run under /bin/sh: dash on Debian and Ubuntu prints /bin/sh: 1: npx: not found, BusyBox on Alpine /bin/sh: npx: not found. In a container it means the image has no Node; one built FROM debian or FROM alpine starts without it. Use an official Node image: it ships npm and npx, and the tag pins the major version.

Dockerfile
FROM node:24-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["npm", "start"]

cron and systemd never read your shell’s startup files, so nvm’s lines do not run there. Install Node system-wide, or set the PATH for the job, with the directory command -v npx prints:

crontab -e
PATH=/home/USER/.nvm/versions/node/VERSION/bin:/usr/bin:/bin
0 3 * * * cd /srv/app && npx PACKAGE

In a systemd unit, the same goes into Environment=PATH=…. Give ExecStart= the absolute path of npx as well: systemd looks a bare command name up in a fixed list of system directories, not in that PATH.

Windows: “'npx' is not recognized as an internal or external command”

cmd prints 'npx' is not recognized as an internal or external command, followed by operable program or batch file. PowerShell 7 says The term 'npx' is not recognized as a name of a cmdlet, function, script file, or executable program. Windows PowerShell 5.1 says “the name of” and “operable program” instead. The causes, most likely first:

  • Node.js is not installed. Install the LTS release with winget (below) or the installer from nodejs.org.
  • The terminal or editor was open during the install. Every program keeps the PATH it started with. Close all terminals and every VS Code window, then open them again.
  • Node’s folder is missing from PATH. The installer adds C:\Program Files\nodejs\. If that option was deselected during setup or the entry was removed later, run the installer again and keep “Add to PATH” selected.
  • nvm-windows with no version selected. After nvm install, run nvm use VERSION; until then no Node is active.
PowerShell · cmd
winget install OpenJS.NodeJS.LTS

In a new window, check where Windows finds it:

PowerShell · cmd
where.exe npx
npx --version

Type where.exe in full: in PowerShell, plain where is an alias for Where-Object and prints nothing useful. The first line should name a file in C:\Program Files\nodejs.

“npx.ps1 cannot be loaded because running scripts is disabled”

npm ships an npx.ps1 next to npx.cmd, and PowerShell runs the .ps1. Windows client editions block all scripts by default (execution policy Restricted), so you get File C:\Program Files\nodejs\npx.ps1 cannot be loaded because running scripts is disabled on this system. Allow local scripts for your account:

PowerShell
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

RemoteSigned still blocks unsigned scripts downloaded from the internet. If you cannot change the policy, type npx.cmd instead of npx, or use cmd.

Editors, AI apps and MCP servers: “spawn npx ENOENT”

An MCP server, editor extension or desktop app that starts npx can fail while npx works in your terminal. Node-based apps report spawn npx ENOENT, Go-based ones exec: "npx": executable file not found in $PATH, and some print their own “npx not found” message asking you to add Node.js and npm to your PATH. On a Mac, most apps started from the Dock or Finder never read ~/.zshrc or ~/.zprofile, so PATH lines from nvm or Homebrew do not reach them. On Windows, an app that was already running during the Node install still has the old PATH.

Put the absolute path from command -v npx into the config, and give the server a PATH with the same directory, because npx needs node next to it:

MCP config (JSON)
{
  "mcpServers": {
    "SERVER_NAME": {
      "command": "/Users/USER/.nvm/versions/node/VERSION/bin/npx",
      "args": ["-y", "PACKAGE"],
      "env": {
        "PATH": "/Users/USER/.nvm/versions/node/VERSION/bin:/usr/bin:/bin"
      }
    }
  }
}

On Windows, npx is npx.cmd, a batch file that an app cannot start without a shell. Use "command": "cmd" with "args": ["/c", "npx", "-y", "PACKAGE"]. After installing Node, quit the app completely and start it again; closing its window is not enough.

Git hooks: “.husky/pre-commit: 1: npx: not found”

Git hooks run with the PATH of whatever started git commit. From a terminal that is your shell’s PATH; from VS Code’s commit button or a GUI git client it is the app’s, which often lacks an npx installed with nvm or Homebrew. On a Mac the hook reports .husky/pre-commit: line 1: npx: command not found, and husky then prints husky - command not found in PATH= followed by the PATH it had. husky 9 loads ~/.config/husky/init.sh before every hook; put nvm’s two lines there, or Homebrew’s shellenv line from above:

~/.config/husky/init.sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

node works, but npm or npx does not

Almost always a distribution package. Debian, Ubuntu and Alpine ship npm, which contains npx, separately from nodejs:

Debian · Ubuntu
sudo apt install -y npm
Alpine
apk add npm

On Debian 12 and Ubuntu 24.04 that still leaves you on Node 18 (Node 12 on Ubuntu 22.04), so switching to NodeSource is usually the better fix. Two commands from older guides make things worse:

  • npm install -g npx installs the old standalone npx package, which npm marks as deprecated: npx is now part of the npm CLI.
  • npm install -g npm@latest on an old Node: npm 12 requires Node 22.22.2 or a later 22.x, 24.15 or a later 24.x, or Node 26 and newer (per npm view npm engines, checked 11 Oct 2026). Install a current Node instead; it brings a matching npm.

Only npm older than 5.2, from 2017, has no npx at all.

Check that it works

bash · zsh
command -v npx
npx --version

The first prints the file the shell runs: /usr/bin/npx for NodeSource or a distribution package, /opt/homebrew/bin/npx or /usr/local/bin/npx on a Mac, a path under ~/.nvm/versions/node/ for nvm. The second prints npm’s version number, because npx is npm’s exec command. Repeat both in a new terminal, and wherever npx failed before: under sudo, in cron, in the app.

If npx works but npx vite offers to download Vite, the project has no local copy: that is vite: command not found, a different fix.

Running Node on a server

Once npx works, run the app under a systemd unit rather than nohup or a screen session, so it survives the SSH session, a crash and a reboot. If npm install stops with gyp ERR!, a dependency compiles native code and the server needs build tools: make: command not found. If you are setting up a fresh box for this, our Hi-CPU KVM line runs on AMD EPYC and suits work that leans on one or two cores rather than many, such as Node builds.

Running a Discord bot with Node? See Host a Discord bot 24/7 on a VPS, or go straight to Discord bot hosting for the plans.

Another tool missing, or a directory to add to PATH for good in bash, zsh and fish? See command not found: the three causes and the fix for every tool.

Frequently asked

How do I install npx?

You do not install it on its own: npx is part of npm, and npm comes with Node.js. Install the current Node.js LTS release (Homebrew or the nodejs.org installer on a Mac, NodeSource on Debian and Ubuntu, winget on Windows) and open a new terminal. On Debian, Ubuntu and Alpine the distribution's nodejs package has no npm, so add the npm package too. 'npm install -g npx' installs an old standalone package that npm marks as deprecated.

Why does my Mac say 'zsh: command not found: npx'?

macOS does not include Node.js, so install it first. If Node is installed, zsh is not loading it: zsh reads ~/.zshrc and ~/.zprofile, never ~/.bashrc or ~/.profile. Add nvm's three setup lines to ~/.zshrc, or Homebrew's shellenv line to ~/.zprofile, then open a new terminal and check with 'command -v npx'.

How do I fix 'npx is not recognized as an internal or external command' on Windows?

Install the Node.js LTS release ('winget install OpenJS.NodeJS.LTS' or the installer from nodejs.org), then close every terminal and editor window and open a new one: programs keep the PATH they started with. 'where.exe npx' should then name a file in Node's install folder. If PowerShell says npx.ps1 cannot be loaded because running scripts is disabled, run 'Set-ExecutionPolicy -Scope CurrentUser RemoteSigned' or type npx.cmd instead.

Related articles

All troubleshooting