The nest command is not found in the terminal
zsh: command not found: nestShort answer
The shell cannot find a nest executable on its PATH. Either the CLI was never installed, or npm linked it into a global bin folder your PATH does not include. Run it through npx, install it globally and add npm's bin folder to PATH, or call it from package.json scripts.
Fix it fast
1Find out which cause you have
Find out whether the CLI is installed and where npm links global executables.
npm ls -g --depth=0 npm prefix -g2Match what you see, then jump to its fix
What does the error look like?
zsh: command not found: nestbash: nest: command not found
Cause 1 of 3
The CLI is not installed
1Check
Look at the global package list from the first step. Also check whether the project itself has the CLI as a dev dependency.
npm ls -g --depth=0 | grep nestjs
npm ls @nestjs/cli2Fix
Install the CLI globally, or skip the install and run it with npx.
npm install -g @nestjs/cli
# or, without installing:
npx @nestjs/cli@latest --help3Verify
The command prints the CLI help.
nest --helpConfirmed by docs.nestjs.com
Cause 2 of 3
npm's global bin folder is not on your PATH
1Check
In global mode npm links executables into the bin folder under the prefix (on Unix, prefix/bin). That folder must be in PATH.
echo "$(npm prefix -g)/bin"
echo "$PATH" | tr ':' '\n'2Fix
Add the folder printed by the first command to PATH in your shell profile (~/.zshrc for zsh, ~/.bashrc for bash), then open a new terminal.
# ~/.zshrc
export PATH="$(npm prefix -g)/bin:$PATH"3Verify
In a new terminal the shell resolves the command.
command -v nest && nest --versionConfirmed by docs.npmjs.com
Cause 3 of 3
The CLI is only installed inside the project
1Check
Local installs link executables into ./node_modules/.bin. That folder is only on the path for scripts started by npm.
ls node_modules/.bin | grep nest2Fix
Run it through npx or an npm script instead of typing it bare.
npx nest build
# or in package.json scripts: "build": "nest build"
npm run build3Verify
The build runs and writes the dist folder.
ls distConfirmed by docs.npmjs.com
How do I stop it coming back?
- Prefer npx or npm scripts so every developer and the CI server use the CLI version the project expects.
- After switching Node.js versions with nvm, reinstall global CLIs: each version has its own global folder.
- Keep the PATH line in the shell profile, not typed by hand in one terminal.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
npm install worked but the command is not found
bash: vite: command not found
npm puts a local install's command in the project's node_modules/.bin, which is not on your shell PATH, so run it with npx or from an npm script.
3 causes, each with a fixBack end
node and npm vanish or are not found when nvm is installed
nvm current prints system in a new shell
nvm adds node and npm to PATH only for the version it has activated.
4 causes, each with a fixBack end
The serverless command is not found in the shell
bash: serverless: command not found
The shell can only run serverless if it is installed globally and the folder npm links global commands into is on PATH.
3 causes, each with a fixBack end
npm or a script fails in WSL with /usr/bin/env: 'bash\r'
/usr/bin/env: 'bash\r': No such file or directory
The \r in the message is a Windows line ending at the end of a script's first line, so Linux looks for a program called bash followed by a carriage return.
2 causes, each with a fixBack end
yarn command not found, or yarn global binaries not found
zsh: command not found: yarn
The shell cannot find the yarn binary or a tool installed with yarn global.
4 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fix