Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

The nest command is not found in the terminal

Errorzsh: command not found: nest

Short 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.

  • Applies to Node.js 22, npm 10, @nestjs/cli 11, zsh, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 -g
  2. 2Match what you see, then jump to its fix

    1. 1npm ls -g does not list @nestjs/cliThe CLI is not installedFix
    2. 2The CLI is listed by npm ls -g, but the shell still says command not foundnpm's global bin folder is not on your PATHFix
    3. 3node_modules/.bin/nest exists, but typing nest in the shell failsThe CLI is only installed inside the projectFix

What does the error look like?

  • zsh: command not found: nest
  • bash: 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/cli

2Fix

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 --help

3Verify

The command prints the CLI help.

nest --help

Confirmed by docs.nestjs.com

Did this fix it?

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 --version

Confirmed by docs.npmjs.com

Did this fix it?

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 nest

2Fix

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 build

3Verify

The build runs and writes the dist folder.

ls dist

Confirmed by docs.npmjs.com

Did this fix it?

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:

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.