Troubleshoot ng command on Windows 10
What to do when npm -g install @angular/cli doesn't work
By: Ajdin Imsirovic 07 November 2019
Sometimes the simplest procedures on the command line can seem like they just won’t work, no matter what. In this article, we look at what to do when npm install -g @angular/cli
doesn’t add ng command to our command line on Windows 10.
Note: This article has been tested to work for Angular 8.
The problem description
Even though you have Node and npm installed on your machine, when you run the npm install -g @angular/cli
command, it doesn’t add the ng
command to your console.
Steps to fix the problem
These steps assume you have Git bash installed.
First, verify your Node and npm version:
node -v & npm -v
Try ng
command just in case:
ng
Next, verify the root level of your globally installed npm packages:
npm list -g --depth=0
Locate the installation folder for your npm:
npm bin -g
The output here should point to the problem. On my system:
- It showed where npm is installed
- It said that npm is not in the PATH env variable
Adding the npm command to PATH env variable
- Press
Winkey E
to open file explorer. - Type
Control panel
into the address bar. - Click System and security, then View advanced system settings
- User Account control popup will appear, confirm the operation to proceed
- In the System Properties window, click the
Environment variables
button - Locate the Path variable in the second list of Environment variables
- Double-click the Path variable to edit it
- Add a new entry, in my case it was:
C:\Users\PC\AppData\Roaming\npm
- Click OK to save changes
Install Angular CLI and make sure it works
Now close the active Git bash window, re-open it, and type the npm install -g @angular/cli --logging=verbose
.
For good measure, after it’s done, you could check the root level of globally installed packages again:
npm list -g --depth=0
It’s safe to close the bash again, then re-open it and run the ng
command again.
This time proper output should appear: instructions on how to use the ng
command, right inside Git bash.