Raghul Rajendran
Raghul Rajendran

Reputation: 486

After installing Angular in windows - ng is not recognized as an internal or external command

I tried to install Angular but after installing I got this error

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

I installed node, npm and git I then received the below comment for installing Angular. I installed after installing I give ng-v comment I found this error.

npm install -g @angular/cli

Upvotes: 7

Views: 42828

Answers (8)

MazBeye
MazBeye

Reputation: 912

In my case, I was using VSCode and WSL.

I was trying to generate a service from VSCode's Angular Schematics and got the same issue.

Meanwhile, the path "./node_modules/.bin/ng" was actually there since the beginning while generating the project from angular cli. It's also included on the devDependencies section in package.json after generating an angular project.

However, it seems that it needs sudo or special permission to invoke the ng command from that particular directory. While, there's no way we can override the command from VSCode.

On the other hand, I also had @angular/cli installed globally.

Uninstalling the project's (local) @angular/cli should do the trick, by using this command:

npm uninstall -D @angular/cli

Therefore, VSCode's angular schematics (or any command that needs it) will try to use the global @angular/cli that you've installed beforehand.

In case you haven't install it, then install it using:

npm install -g @angular/cli.

That should do the trick.

Upvotes: 0

Pramod Mali
Pramod Mali

Reputation: 1808

Add Following path

Just add path to global npm location:

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

The above directory contains "ng" command enter image description here

Upvotes: 1

Nausheen Khan
Nausheen Khan

Reputation: 49

Execute below command:-

npm uninstall -g angular-cli

npm uninstall --save-dev angular-cli

npm cache clean

npm install -g @angular/cli@latest

Try out it for me it worked

Upvotes: 4

RandallTo
RandallTo

Reputation: 395

Spent days on this. Had 2 different machines and one worked like a charm the other I ended up uninstalling VS2017, NodeJs to start clean. I would install Nodejs without VS installed. Reinstall NodeJS then angular/cli and no NG recognized using NodeJS command prompt or any other command prompt. On NPM get it said it was installed in path "c:\ProgramData\Microsoft\VisualStudio\MDA..taco-toolset.." which made no sense since VS was completely gone.
The solution: In c:\Users\YouUserName.nmprc file persisted after uninstalling Nodejs. Delete this file and reinstalled NodeJS then Angular/cli and all was good.

I think this maybe a result of installing VS2017 with node project types. Not sure but it was one big mess which google lead to no solutions.

Upvotes: 1

Abhishek Prakash
Abhishek Prakash

Reputation: 964

I personally never install angular-cli globally. What I do is -

  1. Create a .bin folder some where in your workspace
  2. Use npm npm install @angular/cli
  3. Come back to your root of workspace
  4. Create an angular app using - .\path to .bin\node_modules\.bin\ng new new-app

And you will be good to go.

Upvotes: 1

Sathish Kotha
Sathish Kotha

Reputation: 1111

Add your node js path ex: " C:\Users\DELL\AppData\Roaming\npm" to System Variable source :follow this link

Upvotes: 6

Ajantha Bandara
Ajantha Bandara

Reputation: 1531

Open a new terminal and try again. Sometimes after installing the package, this error message appears if you use the same window.

If not add it to environment variables.

Upvotes: 2

alytvynov
alytvynov

Reputation: 81

Try to run with sudo.
install your node and npm globally

Upvotes: 0

Related Questions