5

I have just started to work with the CLI and when i tried to install the @angular/cli and run the code ng --help

I am getting the following error

'ng' is not recognized as an internal or external command,

I have gone through all the blogs and didn't find any help after following all the procedures listed in the blogs

  1. I have changed the

user variables path : ;C:\Program Files\nodejs\ and system variable : C:\Program Files\nodejs\ ;%AppData%\npm;;

  1. when i ran the command

    npm install -g @angular/cli

i found the following files under node_modules folder

@angular

-cli

---bin

-----ng

cli

I have tried to clean the cache using

npm cache clean 

and then ran the code

ng --version

but i am getting the error as mentioned in the title

Lijin Durairaj
  • 3,341
  • 11
  • 31
  • 50

11 Answers11

30

I have searched long but didn't found the solution. You have to follow these steps:

  1. Install angular/cli globally
  2. Right after installation complete copy the path showing at the same time in terminal
  3. Paste that path in the PATH environment variable
  4. Restart the terminal this will help

AS after

npm install -g @angular/cli@latest

this path is showing like

C:\Users\rizwan.local\share\npm

enter image description here

copy the path and paste it into Environment variable like

enter image description here

save and run ng -v

Enjoy

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
Rixwan
  • 326
  • 1
  • 4
  • 5
6

angular-cli is older version, for new version first

npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli

to install new version

npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli@latest
Hareesh
  • 6,770
  • 4
  • 33
  • 60
2

Apparently, this issue is because of absence of correct 'ng' related environment variables on windows op.
As an alternative to another answers for fixing environment variables, 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.
Note that, you should always run cmd as administrator or transfer (copy & paste) related Environment Variables for your user-account.

Rzassar
  • 2,117
  • 1
  • 33
  • 55
1

I had to do the following to get a current install and add it to my path:

npm uninstall -g angular-cli

npm uninstall -g @angular/cli

npm cache clean --force

npm install -g @angular/cli

Then open Windows Settings/Environment and add the following to the Path variable:

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

Now ng works for me.

tmgirvin
  • 1,487
  • 11
  • 8
1

uninstall node.js

delete all node_modules from your directory

delete npm from AppData>Roaming>

delete npm_cache and all newly generated node files from the c:\users[username} directory.

install node.js

add local path as:

new>PATH>c:\users[username}\AppData\Roaming\npm

keep this before Temp path

in cmd: npm -v node -v C:\Users\693272>npm install -g @angular/cli

ng -v

(here 'ng' error should not come)

and now you can go to some other directory also and create your new project as

everything installed is set globally

C:\Users\693272>cd /

C:>d:

D:>ng new app1 -d

HOPE THIS HELPS!

1

Simple executing below command should do the trick.

npm install -g @angular/cli@latest
Rut Shah
  • 1,093
  • 11
  • 13
1

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 installation path, e.g. 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. Your environment variables must contain both npm and ng paths

Environment Variable - Path

Alternatively, you can also use Node.js command prompt to run ng commands.

M M
  • 655
  • 1
  • 7
  • 16
0

I think your package name is wrong.

Per the github page:

https://github.com/angular/angular-cli

You should use this command instead:

npm install -g @angular/cli

I think angular-cli is the older version.

chrispy
  • 3,552
  • 1
  • 11
  • 19
0

There are two 'PATH' Environment variables, we need to set in 2nd section path variable.

After setting Environment variable %PATH%, in below section, I am able to perform ng commands.

'C:\Users\{username}\AppData\Roaming\npm'.

Brijesh
  • 352
  • 5
  • 17
0

instead of adding to "User variables", it is better to append to Path in "System variables". a new software install can easily erase the "User variables" you just added.

append to Path in "System variables" the following: C:\Users{username}\AppData\Roaming\npm

Feng Zhang
  • 1,698
  • 1
  • 17
  • 20
0

The issue is simple, npm doesn't know about ng

Just run npm link @angular/cli and it should work seamlessly.

Source: see here

Asad Shakeel
  • 1,949
  • 1
  • 23
  • 29