Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng: command not found while creating new project using angular-cli

People also ask

How do I fix ng not found?

If they are proper: Find the root global Directory of NPM npm root -g (it will give you root of your global npm store) Uninstall old angular cli with npm uninstall -g angular-cli and npm cache clean. Reinstall new Version of angular npm install -g @angular/cli@latest.

Why is NG not working?

Error 1: 'ng' is not recognized 'ng' is not recognized as an internal or external command. 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.

How do you fix Ng is not recognized as an internal or external command?

To solve the error "ng is not recognized as an internal or external command, operable program or batch file", install the angular cli globally by running npm install -g @angular/cli@latest and make sure your PATH environment variable is set up correctly.

How do you fix error this command is not available when running the Angular cli outside a workspace?

To Fix Error “This command is not available when running the Angular CLI outside a workspace Error”, Do Right-Click on yours project name in VS Code and Click “Open in Integrated Terminal” Option. It would open the project to your terminal and error would be fixed.


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

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


First, angular-cli is deprecated and has been replaced with @angular/cli. So if you uninstall your existing angular-cli with npm uninstall angular-cli, then reinstall the package with the new name @angular/cli you might get some conflicts. My story on Windows 7 is:

I had installed angular-cli and reinstalled using npm install -g @angular/cli, but after doing some config changes to command-line tools, I started getting the ng command not found issue. I spent several hours trying to fix this but none of the above issues alone worked. I was able to fix it using these steps:

Install Rapid Environment Editor and remove any PATH entries for node, npm, angular-cli or @angular/cli. Node.js will be in your System path, npm and angular entries are in the User path.

Uninstall node.js and reinstall the current version (for me 6.11.1). Run Rapid Environment Editor again and make sure node.js and npm are in your System or User path. Uninstall any existing ng versions with:

npm uninstall -g angular-cli

npm uninstall -g @angular/cli

npm cache clean

Delete the C:\Users\%YOU%\AppData\Roaming\npm\node_modules\@angular folder.

Reboot, then, finally, run:

npm install -g @angular/cli

Then hold your breath and run:

ng -v

If you're lucky, you'll get some love. Hold your breath henceforward every time you run the ng command, because 'command not found' has magically reappeared for me several times after ng was running fine and I thought the problem was solved.


Make sure that the npm directory is in your "Path" variable.

If the module is installed properly, it may work if you start it out of your global node module directory, but your command line tool doesn't know where to find the ng command when you are not in this directory.

For Win system variable add something like:

%USERPROFILE%\AppData\Roaming\npm

And if you use a unix-like terminal (emulator):

PATH=$PATH:[path_to_your_user_profile]/path-to-npm

the easiest solution is (If you have already installed angular) :

1 remove the ng alias if existing

unalias ng

2 add the correct alias

alias ng="/Users/<user_name>/.npm-global/bin/ng"

3 run ng serve for example and it will work.


This is how I made it worked for me :).

1 - npm link @angular/cli

It will return you the path of cli, which will look like this

/usr/local/Cellar/node/11.3.0_1/lib/node_modules/@angular/cli

For this part, /11.3.0_1 please replace this with your respective node version that can be found by typing node --version

2 - cd ~/

3 - open .bash_profile

In the bash profile create an alias for cli like this,

alias ng="/usr/local/Cellar/node/11.3.0_1/lib/node_modules/@angular/cli/bin/ng"

4 - source ~/.bash_profile

This is how your .bash_profile will look like once you add alias to it.

enter image description here

Now typing ng in the terminal will display output shown in attached snapshot.

enter image description here

I hope this answer will be helpful.