[node.js] Angular - ng: command not found

I'm trying to learn Angular and my knowledge in terminal is beginner. After I installed Angular and then type ng new my-project. I get the response ng: command not found. I've seen other posts that had this problem and I've uninstalled and reinstalled npm and ng.

The last step I took was npm install -g @angular/cli@latest then ng new my-project.

Then I get ng: command not found.

This question is related to node.js angular command-line

The answer is


100% working solution

1) rm -rf /usr/local/lib/node_modules

2)brew uninstall node

3)echo prefix=~/.npm-packages >> ~/.npmrc

4)brew install node

5) npm install -g @angular/cli

Finally and most importantly

6) export PATH="$HOME/.npm-packages/bin:$PATH"

Also if any editor still shown err than write

7) point over there .

100% working


Try uninstalling the angular cli installed

npm uninstall -g angular-cli npm uninstall -g @angular/cli

The clean the node cache npm cache clean

Then npm install -g @angular/cli@latest

set Path the path C:\Users\admin\AppData\Roaming\npm\node_modules@angular\cli


just install npm install -g @angular/cli@latest


Removing NODE and using NVM instead fixed a lot of issues.

removing Node from your system

install NVM from here https://github.com/creationix/nvm

Install Node via NVM: nvm install

stable run npm install -g angular-cli

LINK


*Windows only*

The clue is to arrange the entries in the path variable right.

As the NPM wiki tells us:

Because the installer puts C:\Program Files (x86)\nodejs before C:\Users<username>\AppData\Roaming\npm on your PATH, it will always use version of npm installed with node instead of the version of npm you installed using npm -g install npm@.

So your path variable will look something like:

C:\<path-to-node-installation>;%appdata%\npm;

Now you have to possibilities:

  1. Swap the two entries so it will look like
…;%appdata%\npm;C:\<path-to-node-installation>;…

This will load the npm version installed with npm (and not with node) and with it the installed Agnular CLI version.

  1. If you (for whatever reason) like to use the npm version bundled with node, add the direct path to your global Angualr CLI version. After this your path variable should look like this:
…;C:\Users\<username>\AppData\Roaming\npm\node_modules\@angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…

or

    …;%appdata%\npm\node_modules\@angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…  

for the short form.

This worked for me since a while now.


If you are working on Windows then do the following:

From this directory:

C:\Users\ [your username] \AppData\Roaming , delete NPM folder then install Angular using this command npm install -g @angular/cli


For MacOS

Sometimes the ng command does not get established as a link in /usr/local/bin. I fixed the problem by adding it manually:

ln -s /usr/local/Cellar/node/10.10.0/lib/node_modules/angular-cli/bin/ng /usr/local/bin/ng

Before wasting lots of time in installing and uninstalling, read this.

If you already installed angular before and found this issue, may be it is the reason that you installed angular before with running terminal as Administrator and now trying this command without administrator mode or vice versa. There is a difference in these two.

If you installed angular without administrator mode you can only use angular commands such as ng without administrator mode. Similarly,

If you installed angular with administrator mode you can use angular commands such as ng in administrator mode only.


For Linux user

$ alias ng="/home/jones/node_modules/@angular/cli/bin/ng"

then check angular/cli version

ng --version

enter image description here


I had a lot of issues installing it on a mac with all the permission errors Finally the following line solve the issue.

sudo npm i -g @angular/cli


You can install npx to use Angular CLI installed in your directory:

npm install -g npx
npx ng serve

I tried this and everything worked by changing the npm directory.

         mkdir ~/.npm-global
         npm config set prefix '~/.npm-global'
         export PATH=~/.npm-global/bin:$PATH
         source ~/.profile
         npm install -g jshint
         ng --version

Guess You are running on Windows (To make @jowey's answer more straightforward).

  • Install Angular normally from your bash $ npm install -g @angular/cli@latest Next is to rearrange the PATHS to
  • NPM
  • Nodejs
  • Angular CLI

in System Environment Variables, the picture below shows the arrangement.

enter image description here


In my case

OS Version: Ubuntu 18.04.4 LTS

Node version v12.16.0

Remove ng from /usr/local/bin by using below command.

sudo rm -r ng

After that, installed ng by using command mentioned below.

sudo npm install -g @angular/cli


if you have npm, install run the command

npm install -g @angular/cli

then bind your ng using this:

cd

alias ng=".npm-global/bin/ng"

Follow the Pictures for more help.

enter image description here enter image description here enter image description here enter image description here


Step 1 : Delete "npm" folder from the following path

C:\Users\YourUserName\AppData\Roaming

Step 2 : Once you have the "npm" folder deleted, uninstall Node.Js.

Step 3 : Reinstall Node.JS

Step 4 : Install Angular CLI Using this command npm install -g @angular/cli@latest

Step 5: Now try : ng --version or ng -v


The error may occur if the NodeJs is installed incorrectly or not installed at all. The proper way to fix that is to install/reinstall it the right way (check their official website for that), but if you're searching for a quick solution, you can try to install Angular CLI globally:

npm install -g @angular/cli

If it doesn't work and you are in a hurry, use sudo:

sudo npm install -g @angular/cli

Don't forget to reopen your terminal window.


I had that same problem and just solved it.

make sure you have node installed.

after running

npm i -g @angular/cli

when installation is finished, try re-opening your git bash or whatever you're using or open it in a new folder. boom. it worked for me


If you have already installed @angular/cli

Then you only need to link it to npm using npm link @angular/cli

Otherwise first install angular by npm install @angular/cli and then link.


Windows 10 Only

If you are using Git Bash and also you are sure that you have done all steps that are listed above, still getting an error like this, run following command:

alias ng="C:/Users/<your-username>/AppData/Roaming/npm/node_modules/@angular/cli/bin/ng"

then run ng -v

Finally, it works if you see the version of Angular-CLI


You must know the full path of your angular installation. For example: C:\Users\\AppData\Roaming\npm\node_modules@angular\cli\bin\ng . Type in cmd, powershell or bash

alias ng="C:\Users\<your username>\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng"

It may has not helped OP, but it solved my problem. This answer is to help others who have not tried the command mentioned in OP's question.

Just use npm install -g @angular/cli@latest. It did the trick for me.


if you install npm correctly in this way:

npm install -g @angular/cli@latest

and still have that problem, it maybe because you run the command in shell and not in cmd (you need to run command in cmd), check this out and maybe it helps...


>> npm uninstall -g angular-cli
>> npm uninstall -g @angular/cli

>> npm cache clean

Restart you machine

then >> npm install -g @angular/cli@latest

set Path : C:\Users\admin\AppData\Roaming\npm\node_modules@angular\cli

Hope you never get 'ng' not found


Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`

Examples related to angular

error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class error TS1086: An accessor cannot be declared in an ambient context in Angular 9 TS1086: An accessor cannot be declared in ambient context @angular/material/index.d.ts' is not a module Why powershell does not run Angular commands? error: This is probably not a problem with npm. There is likely additional logging output above Angular @ViewChild() error: Expected 2 arguments, but got 1 Schema validation failed with the following errors: Data path ".builders['app-shell']" should have required property 'class' Access blocked by CORS policy: Response to preflight request doesn't pass access control check origin 'http://localhost:4200' has been blocked by CORS policy in Angular7

Examples related to command-line

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Flutter command not found Angular - ng: command not found how to run python files in windows command prompt? How to run .NET Core console app from the command line Copy Paste in Bash on Ubuntu on Windows How to find which version of TensorFlow is installed in my system? How to install JQ on Mac by command-line? Python not working in the command line of git bash Run function in script from command line (Node JS)