ng is not recognized as an internal or external command, operable program, or batch file

Issue Description

After installing the Angular CLI, ng is not recognized as an internal or external command.

 'ng' is not recognized as an internal or external command, operable program or batch file.

OR

The term 'ng' is not recognized as the name of a cmdlet

ng is not recognized ng the term'ng' is not recognized as the name of a cmdlet, function, script file, or operable program.

Resolution

This error I found to be due to improper configuration of Angular CLI in the target machine. This issue generally occurs post-installation of CLI.

Below are the few steps that I followed and how I was able to fix this issue.

Steps to fix – ng is not recognized issue

  • Before providing the below fixes, please make sure to run the below command in the Node.js command prompt

ng --version

If the above ng commands work, then you are all set! If the issue persists, please look into the below steps.

  • Let’s clear off the local cache and uninstall the existing Angular CLI Version.

npm uninstall -g @angular/cli 
npm cache clean  --force

  • In addition to the above make sure %appdata% doesn’t have the below folders etc.

This additional precaution is to avoid any issues further. I

I am sure you must have tried a few other options already with no luck.

Please delete if any such folder exists from %appdata% and npm folders

ng is not recognized

Re-install Angular CLI globally

Please run the below command in Admin mode from Command Prompt (Preferred).

For a few of you, this command might work in regular CMD as well.

ng update @angular/cli @angular/core

Add the below path to an environment variable. First, try updating in User Variable section ‘Path‘ variable.

 C:\Users\{userName}\AppData\Roaming\npm

OR

%USERPROFILE%\AppData\Roaming\npm

Example:

'ng' is not recognized as an internal or external command, operable program or batch file.

Please try running the ng –version in the new cmd window.

Tops- Before running this command make sure to close all existing open , command prompts or node.js command prompt. This is required once you make any changes to the environment variable.

If the issue persists, please set the below path in a local variable in a similar way.

 C:\Program Files\nodejs\node_modules\npm\bin

Now please try running the ng –version again in a new command prompt.

Again before running this command make sure to close all command prompt/node.js command prompts.

If the issue persists, please set the below path in the Local variable

C:\Users\{username}\AppData\Roaming\npm\node_modules\@angular\cli\bin

OR

%USERPROFILE%\AppData\Roaming\npm\node_modules\@angular\cli\bin 

Close all command prompts and try running the ng –version again.

If the issue persists, please perform the above steps for the System Variables section and Path variable and repeat the above steps for the system variable.

You shall see ng commands working on all CLI interfaces in your machine.

CLI

blank

Powershell

ng the term'ng' is not recognized as the name of a cmdlet, ng is not recognized

VSCode (powershell)

ng the term'ng' is not recognized as the name of a cmdlet

References:

Did I miss something in these steps? Did the above steps resolve your issue?

Please sound off your comments below!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



17 thoughts on “Resolved: ng is not recognized as an internal or external command

  1. If I will open a differnt user then run ng serve it’s giving me error
    ng’ is not recognized as an internal or external command’

    1. Hello Pankaj- Thanks for your query . Please set the User environment variable for every new user.
      If you set those 2 variable as System environment variable then i think that should works even if you chnage the user.

      1. Did you perform Angular CLI installation for new %USERPROFILE% as well? see if npm install -g @angular/cli@latest commands for new profile works for you.

Leave a Reply

Your email address will not be published. Required fields are marked *