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.

What to do when npm install -g @angular/cli does not work

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:

  1. It showed where npm is installed
  2. It said that npm is not in the PATH env variable

Adding the npm command to PATH env variable

  1. Press Winkey E to open file explorer.
  2. Type Control panel into the address bar.
  3. Click System and security, then View advanced system settings
  4. User Account control popup will appear, confirm the operation to proceed
  5. In the System Properties window, click the Environment variables button
  6. Locate the Path variable in the second list of Environment variables
  7. Double-click the Path variable to edit it
  8. Add a new entry, in my case it was: C:\Users\PC\AppData\Roaming\npm
  9. 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.

Feel free to check out my work here: