85

I tried running npm install -g angular-cli

enter image description here

I also tried adding it to the Enviorment Variables under PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) , with no success also. enter image description here

4

19 Answers 19

141

You can also try:

 > npm run ng <command>
0
81

I had the same issue on Windows7. I resolved it setting correct path.

  1. First find ng.cmd file on your System. It will usually at:

    E:\Users\<USERNAME>\AppData\Roaming\npm
    
  2. Set PATH to this location.

  3. Close existing command window and open new one

  4. Type

    ng version
    

Also remember to install angular with -g command.

npm install -g @angular/cli
3
  • 3
    This should be the valid answer. Commented Oct 18, 2018 at 4:10
  • 1
    I had to also add the E:\Users\<username>\AppData\Roaming\npm\node_modules\@angular\cli folder to the path in order for it to work
    – th3morg
    Commented Feb 15, 2019 at 16:06
  • 1
    executing npm install -g @angular/cli solved my issue. Thanks for the answer
    – Rajan
    Commented Sep 10, 2019 at 13:58
73

This error is simply telling you that Angular CLI is either not installed or not added to the PATH. To solve this error, first, make sure you’re running Node 6.9 or higher. A lot of errors can be resolved by simply upgrading your Node to the latest stable version.

Open up the Terminal on macOS/Linux or Command Prompt on Windows and run the following command to find out the version of Node you are running:

node --version
3
  • 3
    It didn't for me; could anyone advise please?
    – Maha Rizk
    Commented May 9, 2018 at 7:24
  • 15
    in the windows command i tried "npm run ng build" and it worked fine thank you
    – Maha Rizk
    Commented May 9, 2018 at 7:26
  • 11
    npm run ng test in the command prompt give me: npm ERR! missing script: ng . I installed @angular/cli globally (npm install -g @angular/cli)
    – Alex 75
    Commented Dec 2, 2018 at 20:44
50

You should not add C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng to your PATH. There is only a javascript file which you cannot use in terminal.

You need ng.cmd which is probably located at %AppData%\npm. Make sure this path is included in your PATH variable.

4
  • i had done something similar, added /node_modules in path. Thanks Commented Sep 13, 2018 at 14:46
  • 5
    %AppData%\Roaming\npm should be %AppData%\npm Commented Mar 4, 2019 at 12:06
  • 1
    @ChamikaSandamal It depends on your setup. In this case, OP has prefix of npm set to %AppData%\Roaming\npm Commented Mar 5, 2019 at 10:56
  • what if I use yarn?
    – serge
    Commented May 25 at 21:20
13

I was with the same problem and now discovered a working solution. After successful installation of node and angular CLI do the following steps.

Open C:\usr\local and copy the path or the path where angular CLI located on your machine.

enter image description here

Now open environment variable in your Windows, and add copied path in the following location:

Advanced > Environment Variable > User Variables and System Variables as below image:

enter image description here

That's all, now open cmd and try with any 'ng' command:

enter image description here

11

You should add the path where ng.cmd located. By default, it should be located on C:\Users\user\AppData\Roaming\npm

NB: Here "user" may vary as per your pc username!

0
8

make sure environment variables are set properly.

control panel-> system->advanced system settings-> select advanced Tab->
click on environment variables

and make sure in the path below line is available

`C:\Users\username\AppData\Roaming\npm`   

here username will get changed based on the user

.

still if its not working yourenvironment variables are not getting reflected so please restart your machine it will work fine

if still you are facing issue your angular cli is not installed properly

please run below commands for reinstalling

   npm uninstall -g @angular/cli

    npm cache clean    or   npm cache clean  --force

    npm install -g @angular/cli@latest
1
  • npm install -g @angular/cli@latest command worked for me. Thanks
    – Ish
    Commented Apr 21, 2022 at 4:45
7

Just adding a little info to the previous answers, If you have windows 7 or above then go to start and search Node.js command prompt and you will be directly shown the app. Click on it, and start working by using that command prompt for angular.

1
  • 1
    Thanks, man! It solved my problem in which I was stuck for days Commented Jan 6, 2023 at 15:54
7

This answer is based on the following answer by @YuSolution https://stackoverflow.com/a/44622211/4567504.

In my case Installing MySQL changed my path variable and even after reinstalling @angular/cli globally many times I was not able to fix the issue.

Solution:

In command prompt, run the following command

npm config get prefix

A path will be returned like

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

Copy this path and go to ControlPanel > System and Security > System, Click on Advanced System settings, go to advanced tab and select environment variable button like

enter image description here

Now in User Variables box click on Path row and edit and in variable value box paste your copied path.

Restart the command prompt and it will work

3

note: you may lose values once system restarts.

You can also add system environment variables without Admin rights in Windows 10.

Go to Control panel --> user accounts

Change my environment variables

environment variables --> select **Path** and click edit

click **New** and add path to it

now don't restart, close any opened cmd or powershell, reopen cmd and test by ng version command if you see this it is confirmed working fine.

ng version --> Angular cli

hope this helps

2

If angular cli is installed and ng command is not working then please see below suggestion, it may work

In my case problem was with npm config file (.npmrc ) which is available at C:\Users{user}. That file does not contain line registry https://registry.npmjs.org/=true. When i have added that line command started working. Use below command to edit config file. Edit file and save. Try to run command again. It should work now.

npm config edit
2

You don't need to set any path. Follow the below step to resolve the problem-

Step 1- go to

C:\Users\user\AppData\Roaming and delete npm, npm-update and npm-cache folder

Step 2- run

npm install -g @angular/cli@yourangularversion again.
0
2

No need to uninstall angular/cli.

  1. You just need to make sure the PATH to npm is in your environment PATH and at the top.

C:\Users\yourusername\AppData\Roaming\npm

  1. Then close whatever git or command client your using and run ng-v again and should work
2

I have tried with this below Steps and its working fine:-

Download latest version for nodejs, it should work

1
  • 1
    I tried reinstalling angular cli and messing with Windows PATH, neither worked. Installing latest version of nodejs as suggested fixed my problem.
    – hamid reza
    Commented May 12, 2020 at 6:47
2

I just installed angular cli and it solved my issue, simply run:

npm install -g @angular/cli
1

What worked for me was that I was missing an file

.npmrc

which is located under

C:\Users\username

That file should contain

prefix=$(APPDATA)\npm

Also my environment path was pointing to my admin user

1

npm update solves the issue for me

1

This issue also bother me and then i find possible cases to reproduce this issue

when i run my window in administrator then it working fine ng but when i run this in my second space like other user then i got this issue.

so if i want to run my angular application then i need to run this command

npm run ng serve which is working but when i run the command with --host npm run ng server --host IP it not working given some error

so i find some possible solution 1. go appdata and then user\admin\AppData\Roaming\npm folder then copy this path but if you using other user account user\newuser\AppData\Roaming\npm folder you can copy this npm folder from other user i.e admin user account. if you do not want to copy this folder then copy the path of ****user\admin\AppData\Roaming\npm folder**** folder and then open your environment variable setting and add this path in path variable name

enter this path in system path variable not user variable C:\Users\admin\AppData\Roaming\npm

enter image description here enter image description here and run the command prompt as administrator then run ng command it will work enter image description here enter image description here enter image description here

0

Short answer:

Just install the latest version of nodejs and then restart your system.

more description:

It's related to Environment variables in your system at least as far as I know, you can make changes in path variable in your system as others talked about it in the current thread but the easiest way to solve this is installing nodejs!

Not the answer you're looking for? Browse other questions tagged or ask your own question.