397

Running windows 7 Professional 32bit.

I tried running npm install -g angular-cli both under normal or admin. 2016-06-23_14h46_40

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.
2016-06-23_14h56_48

What am i doing wrong?

15
  • 7
    Surely you want the directory (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin) in %PATH%?
    – Biffen
    Commented Jun 23, 2016 at 12:25
  • I'm not sure. I tried it just to see if 'ng' works, but it doesn't. Commented Jun 23, 2016 at 12:46
  • 3
    Well, check that %PATH% contains (it's a semicolon-separated list) the directory that contains ng.exe.
    – Biffen
    Commented Jun 23, 2016 at 12:48
  • 3
    i found the solution for that problem stackoverflow.com/a/46874999/7968316
    – Rixwan
    Commented Oct 22, 2017 at 14:16
  • 1
    @Cristian Muscalu Or you can simply run cmd as admin (if you can) and install angular-cli from there. so environment variables would be automatically fixed for you.
    – Rzassar
    Commented Apr 8, 2018 at 5:02

55 Answers 55

523

I solved this problem in accordance with the figure:

run in cmd

 npm install -g @angular/cli

and then

( open in Windows 10) Control Panel\All Control Panel Items\System or accordance with the figure

step 1:

enter image description here

step 2 :

enter image description here

step3:

enter image description here

step4:

enter image description here

step5: add missing ng path

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

enter image description here

Here is new environment variable that you need add: C:\Users\PK\AppData\Roaming\npm\node_modules\@angular\cli\bin

Finally, restart all opened command prompts and try again.

13
  • you got the Angular and NG comments (in res) the wrong way round ;)
    – Shaheen K
    Commented Sep 19, 2017 at 10:32
  • 7
    in my case i only needed to add the path to npm.
    – Kieran
    Commented Mar 13, 2018 at 22:09
  • 85
    You don't have to restart the computer at the end, u just have to restart the command prompt. Commented May 1, 2018 at 9:10
  • 18
    Rather than C:\Users\<YOURUSER>\AppData\Roaming\npm, you can use %USERPROFILE%\AppData\Roaming\npm without having to type in your username.
    – dana
    Commented Jun 7, 2021 at 17:10
  • 7
    This instructions are overcomplicated, just hit the WINDOWS key and type "Environment" to go to the environment variables Commented Apr 2, 2022 at 0:21
358

For me it works with:

npm run ng <command>
9
  • 17
    Do you know the reason why it is so and how can we get rid of 'npm run' ?
    – Pratik
    Commented Jan 12, 2018 at 6:30
  • 6
    but this does omit any additional parameters after ng build
    – hakuna
    Commented Apr 10, 2018 at 19:28
  • For direct running through ng command you can link your @angular/cli with npm using npm link @angular/cli Commented Jul 5, 2019 at 12:35
  • 8
    @PratikGandhi This is because cmd can only run commands specified in the environment variables (in this case npm). This path is added when you install node in your system globally. When you add the complete path C:\Users\<user>\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng to environment variables and rerun cmd, it will accept ng as a command. Alternatively, you can also use Node.js command prompt to run ng commands.
    – M M
    Commented Jul 28, 2019 at 16:55
  • 3
    @hakuna You can pass in additional parameters to the ng command via npm run ng serve -- --port=12345. Note the two separate sets of dashes.
    – krillgar
    Commented Sep 22, 2020 at 19:09
140

Adding C:\Users\DELL\AppData\Roaming\npm to System Variable Path worked for me. Please find your appropriate file path to 'npm'

Also, check if you have added your angular-cli\bin path to the path variable.

5
  • 5
    Also try restarting PC. After that ng command started working.
    – cah1r
    Commented Feb 6, 2017 at 8:25
  • 2
    Look up the path for file "ng.cmd". update the environment variable PATH with the path.
    – Jnana
    Commented Jun 3, 2017 at 2:50
  • 4
    This worked for me on Windows 10, but I added "%USERPROFILE%\AppData\Roaming\npm" to cover multiple potential users pulling from their own user profiles. Commented Sep 28, 2017 at 19:29
  • 4
    %AppData%\npm will expand to both @TimMcElwee and @sabari's values, and are user and machine agnostic.
    – ps2goat
    Commented Sep 27, 2018 at 16:04
  • adding the \npm folder to path variables fixed it for me
    – Kaspazza
    Commented Feb 13, 2020 at 9:15
98

I am using WIN 10, just figure it out for this problem. Type the code below in cmd:

npm config get prefix

and copy&paste the path that you get it from the top into your computer environment variables-->user variables box --> path --> edit -- C:\Program Files\nodejs\node_global, your path may different.

Click Ok and reopen your cmd window, type in ng version, then it works! Cheers!

3
  • 1
    Works like a charm! MySQL shell overrode my user path variable.. :( Commented Sep 13, 2019 at 9:49
  • 1
    Didn't work for me. npm config get prefix told me my directory was C:\Users\PhilVanKleur\AppData\Roaming\npm\ . But there's nothing in it. Commented Nov 20, 2020 at 15:59
  • This worked perfectly for me in Win 10 on my Dev box. I have also installed Chocolatey and ran the "refreshenv" command after adding the folder which was yielded into the user environment PATH variable and avoided to have to refresh my terminal window. Commented Nov 27, 2021 at 20:40
55

Just open your command prompt (run as administrator). Ensure node --v is 6.9.0 or higher and npm --v is 3.0.0 r higher.

After that run the following command:

npm install -g @angular/cli

Once angular is installed. you can see an entry of angular cli in the path

C:\Users\Dell\AppData\Roaming\npm\node_modules\@angular

Then try ng help. It will work.

1
  • running as administrator seems to be the key bit
    – tony
    Commented Dec 24, 2020 at 14:54
50

1) Enter below command on command prompt

npm install -g @angular/cli

2) Make sure that C:\Users\_username_\AppData\Roaming\npm this path is not hidden.

3) Add C:\Users\_username_\AppData\Roaming\npm and

C:\Users\_username_\AppData\Roaming\npm \node_modules@angular\cli\bin to both enviroment variable path.

4) Open new command prompt and type ng help. It will work.

2
  • I could not see the AppData directory until I got admin permission for my Windows 10 machine and then opened up a command window by clicking Run as Administrator. Commented May 14, 2020 at 15:30
  • I had that folder hidden but it still worked. This is the best solution. As an FYI if needed: you separate the paths with a semi-colon so it becomes: <what's already there>;C:\Users\_username_\AppData\Roaming\npm;C:\Users\_username_\AppData\Roaming\npm \node_modules@angular\cli\bin
    – Corné
    Commented Jul 5, 2020 at 1:24
24

With a command

npm install -g @angular/cli@latest

It works fine, I am able to run ng command now.

1
  • I ran npm install -g @angular/cli@latest from folder c:\Temp. It did not install to C:\Users_username_\AppData\Roaming\npm \node_modules@angular\cli\bin. It created C:\Temp\node_modules instead. I'm very new to this but I thought -g (global) would put it in ..Appdata\Roaming\npm.. Commented Jun 1, 2021 at 11:37
23

I followed below steps for resolution for this issue in Windows 10:

  1. First make sure you have installed Angular CLI . You can use below to install same.

npm install -g @angular/cli@latest

  1. Make sure that AppData is visible and navigate to path below.

C:\Users\rkota\AppData\Roaming\npm

Same path can be found by running below too:

npm config get prefix

  1. Add the above path i.e. " C:\Users\rkota\AppData\Roaming\npm" in Environment variable PATH and make sure it got added by running path in command prompt.
  2. Close command prompt and now try to run below:

ng --version

you will be able to see CLI version.

23

I solved it after having the same problem with other global modules, by adding to:

Environment Tables -> System variables -> Path:

C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin;C:\Program Files\MongoDB\Server\3.2\bin

Note that it must not have any spaces after ;

4
  • Look up the path for file ng.cmd. Update the environment variable PATH value with the same path path. Restart the command line console and you are done.
    – Jnana
    Commented Jun 3, 2017 at 3:03
  • 3
    The answer below "npm config get prefix" is the correct approach Commented Feb 23, 2018 at 17:08
  • 2
    unless you see the ng in the folder is ng.cmd or Windows Command Script under Type column, else this ng in this angular-cli\bin does not work.
    – Jeb50
    Commented Jun 15, 2018 at 18:53
  • 1
    this answer needs updating, as now the path in CLI v7.0+ is C:\Users\UserName\AppData\Roaming\npm
    – Hemendra
    Commented Feb 26, 2019 at 9:14
19

General problem is that OS tries to find the PATH variable with ng keyword and cannot find it. For me, even after the steps @behrouzmoslem suggested in the top answers to this post I didn't manage to get it work, because after the launch of ng command OS started to respond, but opens up editor file by the path C:\Users\{username}\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng which is actually funny. So, solution is:

Just use npx before any angular executables.

Eg : npx ng serve for serving the angular app or npx ng build --watch to build with watcher.

1
  • Finally! Something that works. I have to run everything from a separate admin account on my machine due to my organisation's security policies. This is the first solution that worked for me. Commented Apr 2, 2023 at 15:16
17

execute following lines in order to solve the issue for both not found and undefined version of ng

npm uninstall -g angular-cli

npm uninstall --save-dev angular-cli

npm cache clean

npm install -g @angular/cli@latest

13

Instead of using the in-built command prompt better start using the NodeJS installed version of command prompt. Then it is going to work perfectly without any issues.enter image description here

1
  • 2
    Running where ng within that console might help to find out what is wrong with the path. That did it for me, ng was resolved in the wrong user AppData, hence executing a bad version of the cli.
    – Frederik.L
    Commented Feb 19, 2018 at 22:49
12

Since it is a Node script I am using the below option to create.

node C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng version

May be symbolic links are required. Not researched further.

On Further Research: Set Path as : %PATH%;C:\Users\Administrator\AppData\Roaming\npm;

In Windows, npm.cmd file is in the above path. If the above Environment variable is set, you can execute as ng version ng init

9

for me it works only with the flag --force:

npm install -g @angular/cli --force

If everything is fine then you shoud see the folder node_modules in this path:

C:\Users\YOUR_USERNAME\AppData\Roaming\npm\
1
  • It's working. thanks. Most of office system is shared workspace like citrix. so, we can't find C drive. But this command will helps to do ng version avail globally. thanks
    – gnganapath
    Commented Jun 3, 2022 at 5:56
8
  1. Open cmd and type npm install -g @angular/cli

  2. In environment variables, add either in the user variable or System variable "Path" value=C:\Users\your-user\.npm-packages\node_modules\.bin

  3. In cmd: c:\>cd your-new-project-path

  4. ...\project-path\> ng new my-app

    or ng all-ng-commands

8

I resolved by adding - %AppData%\npm\node_modules@angular\cli\bin\ path to my environment variables path

6

I faced same issue when i tried to install angular cli locally with command

npm install @angular/cli@latest

After that i got same issue C:\Users\vi1kumar\Desktop\tus\ANGULAR\AngularForms>ng -v 'ng' is not recognized as an internal or external command, operable program or batch file

Than i tried to install it globally

npm install -g @angular/cli@latest

In this case it worked I was wondering that is it not possible to install cli globally ?

After doing some research I found this article very helpful hope it will help someone facing similar issue

Working with multiple versions of Angular CLI

6

Close cmd and open it again with admin rights or reboot your system.

0
5

This one almost worked for me, but I had to use: %USERPROFILE%\AppData\Roaming\npm . In Environment Variables.../System variables/Path

Then when I did CMD: "ng -v" I got the correct response for angular cli.

0
5

npm install -g @angular/cli helped for me instead of npm install @angular/cli

5

1- Install

$ npm install -g @angular/cli

2- Make sure where your ng.cmd is present.

enter image description here

3- Then add this path into variables.

enter image description here

3

I had the same problem on Windows 7, 64 bits running with npm v3.10.8.

  1. I added the path as it was suggested: ( C:\Users.....(your user name)\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) and uninstalled angular-cli.
  2. After this, I cleared the npm cache by npm cache clean as prompted here https://blogs.msdn.microsoft.com/matt-harrington/2012/02/23/how-to-fix-node-js-npm-permission-problems/. This guarantees there are no leftovers.
  3. Reinstalled angular-cli with npm install -g angular-cliand voila.

    Hope that may be useful!
3

In my case I did below steps.

All Programs -> Node JS-> Right click on Node.js Command Prompt and select properties and from Target string at end copy below

/k "C:\Program Files\nodejs\nodevars.bat"

I launched Visual Studio Code and opened below file

C:\Users\gochinta\AppData\Roaming\Code\User\settings.json and gave below

// Place your settings in this file to overwrite the default settings
{
  "terminal.integrated.shellArgs.windows": 
  ["/k", "C:\\Program Files\\nodejs\\nodevars.bat"]

}

Now I typed ng -v in my Visual Studio Code Terminal window and it worked.

3

I was having the same issue when tried with the syntax "ng new " and solved that simply by updating the existing node version from 5.x.x to 8.x.x. After successful updation of node, the syntax worked perfectly for me. Please update the existing version of node. As it is clearly mentioned in angular documentation that these commands require the node version >= 6.9.x. For reference please check https://angular.io/guide/quickstart. It clearly states "Verify that you are running at least node 6.9.x and npm 3.x.x by running node -v and npm -v in a terminal/console window. Older versions produce errors, but newer versions are fine".

3

I faced same issue on x86, windows 7;

  • uninstalled @angular/cli
  • re-installed @angular/cli
  • checked & verified environmental variables (no problems there)...
  • Still same issue:

Solution was the .npmrc file at C:\Users{USERNAME}... change the prefix so that it reads "prefix=${APPDATA}\npm"... Thanks to this website for help in resolving it

3

For me something was wrong in the PATH enviroment variable. I removed all path related to npm and added at the start of PATH this folder:

c:\Users\<your-user-name>\AppData\Roaming\npm\

Make sure you have ; between paths.

1
  • this is the right one, because both Win7 & 10 have ng. cmd file here.
    – Jeb50
    Commented Jun 15, 2018 at 18:57
2

Install x32 version nodejs instead of x64 version (even on 64-bit windows machine).

2
  • Run npm run ng serve for a dev server. Navigate to http://localhost:PORT YOU DEFINE IN APPSETTINGS/. The app will automatically reload if you change any of the source files. Commented Jun 1, 2021 at 10:53
  • @NitishKumar , Why a x32 version instead of x64 on a 64-bit windows?
    – Pinka
    Commented Jan 11, 2022 at 7:15
2

I had the same problem today and have gone through the following path - (%USERPROFILE%\AppData\Roaming\npm) and came to know that there is some junk data and when I cleared everything under npm directory. Now when I ran (npm install command again). Now everything works fine.

1
  • This helped for me!
    – mavi
    Commented Oct 1, 2020 at 20:38
2

I am facing same issue and it's get resolved. At my end reason is i install node and CLI using other user profile and now i am running ng command from other user login. Since node and cli installed using other user login node is not finding anything on C:\Users\&lt;user name&gt;\AppData\Roaming this path and that's why i am getting this error.

I run npm install -g @angular/cli command and restart my machine. Every thing is working fine.

2

Sometime in the future. Applicable to Windows 8.1 machine. Run the following commands

npm install -g @angular/cli

Log out or restart your machine.

This should add the required env path, rather than doing it manually.

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