Fixing `next: command not found` and Other Next.js Install Errors

The next: command not found error means the shell cannot find the next binary. Learn the causes and the fixes.

6 min read

When your shell cannot find the next executable, it prints an error telling you exactly that. It almost always means next is not installed globally, and you are running the command outside the project's npm scripts. Here is the exact message:

texttext
next: command not found

In zsh the same problem appears as zsh: command not found: next. Either way the meaning is the same: your shell looked for a program named next and could not find one.

Why the command is not found

The next package is a local dependency, installed into node_modules inside your project. It is not a global command, so typing next directly fails unless you run it through a script or npx.

  • You typed next instead of npm run dev.
  • Dependencies were never installed, so node_modules is empty.
  • You ran the command from a folder without a package.json.

In all three cases, the project itself is fine. The fix is about how you run the command, not about your code.

Fix 1: use the project scripts

The standard way to run a Next.js app is through the scripts defined in package.json. Run the dev script instead of typing next directly:

bashbash
npm run dev

npm knows how to resolve the local next binary and runs it for you. This is the fix in most cases.

Fix 2: install the dependencies

If the dev script is missing or node_modules is empty, install the dependencies first. This restores the local next binary that the scripts rely on:

bashbash
npm install

After this, npm run dev finds the next binary and the server starts.

Fix 3: run it through npx

For a one-off command, npx locates the package on demand and runs it without a permanent install:

bashbash
npx next dev

This is handy for testing a command, but the project scripts are cleaner for daily work.

Other install errors

These failures happen during setup rather than at the prompt, and each has a simple fix:

  • Node version. Next.js needs Node.js 20.9 or newer, so check with node --version.
  • Wrong folder. Run commands from the folder that contains package.json.
  • Network failures. A failed install leaves node_modules incomplete, so rerun npm install.

Confirm it is fixed

Run npm run dev and watch for the dev server banner in the terminal. The server then serves the app at localhost:3000, which confirms the command resolves and the project is installed. The error should not return.

To set up a project from scratch, read How to Create a Next.js App with create-next-app. For every command the CLI offers, read The Next.js CLI: Every Command and Flag Explained.

Rune AI

Rune AI

Key Insights

  • The error means the shell cannot find the next executable.
  • next is a local dependency, not a global command.
  • Run npm run dev instead of typing next directly.
  • Run npm install if node_modules is missing.
  • Use npx next for one-off commands.
RunePowered by Rune AI

Frequently Asked Questions

Why is next not found even after npm install?

The next package installs locally into node_modules, so the next command only resolves through npm scripts or npx. Running next directly fails because it is not on your PATH.

Can I install next globally?

You can, with npm install -g next, but it is not recommended. Using the project's dev script keeps the version pinned to the project.

What Node.js version does Next.js need?

Node.js 20.9 or newer. An older Node install fails during the dependency step, not just at the command prompt.

Conclusion

next: command not found almost always means you ran the next binary directly instead of through the project scripts. Use npm run dev, install the dependencies, or fall back to npx next.