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:
next: command not foundIn 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:
npm run devnpm 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:
npm installAfter 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:
npx next devThis 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
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.
Frequently Asked Questions
Why is next not found even after npm install?
Can I install next globally?
What Node.js version does Next.js need?
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.
More in this topic
`generateMetadata` Explained with Real Examples
What generateMetadata does, when it runs, and how to use it for real routes: awaited params, deduplicated data fetching, extending parent metadata, and returning a 404 from metadata.
Canonical URLs in Next.js: `metadataBase`, `alternates.canonical`, and Dynamic Pages
How canonical URLs work in the Next.js App Router: setting metadataBase once, writing alternates.canonical per route, handling dynamic segments, and what happens when the base URL is missing.
Open Graph and Twitter Card Metadata in Next.js
How to write Open Graph and Twitter card metadata in the Next.js App Router: the openGraph and twitter fields, automatic card defaults, article tags, and image merge rules.