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

Viewed 26286

I try 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 gived below comment for installing Angular.I installed after installing i give ng-v comment i found this error.

npm install -g @angular/cli

8 Answers

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

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

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.

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.

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

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

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.

Related