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
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
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:
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
Powershell
VSCode (powershell)
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.
This is nice. Perfectly resolved the issue
Thanks Dumindra. Glat it helped you!
Thank you. Worked for me !
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’
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.
I’ve change second user name but it’s still not working ?
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.
You saved me a ton of time!..Thanks a lot!
Thanks Indu. Glad to help you!
Thanks, it worked for me.
Thanks, Harpreet for confirming. Appreciate it!
Thanks for sharing.
Thanks Dileep. Appreciate your comments.
Kudos to you .. worked for me after using Admin mode as mentioned and running all given command.
Thanks worked for me. Seriously, I struggled for this issue for almost 2 weeks.
Thank you ! It worked for me !!
Thanks Berut for your inputs.