The terminal says 'ng: command not found' after installing Angular
ng: command not foundShort answer
The shell finds ng only if the Angular CLI is installed and npm's global bin folder is on your PATH. Check where npm links global commands, compare it with PATH, and either add that folder or install the CLI again. Inside a project you can also skip the global install and run npx ng.
Fix it fast
1Find out which cause you have
Ask npm where global commands are linked, then check that this folder is in PATH. On Unix, executables go to the bin folder under that prefix; on Windows they go straight into the prefix.
npm config get prefix echo $PATH | tr ':' '\n' npm ls -g --depth=02Match what you see, then jump to its fix
- 1
npm ls -g does not list @angular/cliThe Angular CLI was never installed globallyFix - 2
npm ls -g lists @angular/cli, yet the shell still says command not foundnpm's global bin folder is not on PATHFix - 3
ng works in one terminal or after one nvm use, and disappears in anotherThe install went to a different Node.js than the one your terminal usesFix
- 1
What does the error look like?
ng: command not foundzsh: command not found: ng'ng' is not recognized as an internal or external command, operable program or batch file.
Cause 1 of 3
The Angular CLI was never installed globally
1Check
The package is installed per project by default. A project copy puts ng in node_modules/.bin, not on your PATH.
npm ls -g --depth=0 | grep angular2Fix
Install the CLI globally, using Node.js at the version the Angular docs list as supported.
npm install -g @angular/cli3Verify
Open a new terminal and print the version.
ng versionConfirmed by angular.dev
Cause 2 of 3
npm's global bin folder is not on PATH
1Check
Global executables are linked into the prefix's bin folder on Unix. If that folder is missing from the PATH output, the shell cannot see ng.
ls "$(npm config get prefix)/bin" | grep ng2Fix
Add the folder to PATH in the startup file your shell actually reads, then reload it.
# example for zsh; use your own shell's startup file
echo 'export PATH="$(npm config get prefix)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc3Verify
The command resolves to a path inside the prefix.
which ngConfirmed by docs.npmjs.com
Cause 3 of 3
The install went to a different Node.js than the one your terminal uses
1Check
Each Node.js installation has its own global prefix, so a global package follows the Node.js version that installed it.
which node
npm config get prefix2Fix
Stay on one Node.js installation, then reinstall the CLI under it.
npm install -g @angular/cli3Verify
ng and node come from the same prefix.
which node
which ngConfirmed by docs.npmjs.com
How do I stop it coming back?
- Change npm's prefix to a folder in your home directory once, so global installs do not need sudo and the PATH line is permanent.
- Inside a project, run ng through npm scripts or npx so the project's own CLI version is used.
- Open a new terminal after changing PATH; an old window keeps its old environment.
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 -g fails with EACCES on /usr/local/lib/node_modules
npm error syscall access
EACCES means npm tried to write global packages into a folder your user does not own, usually /usr/local/lib/node_modules.
2 causes, each with a fixBack end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fix