Angular CLI ng command not found on Mac Os

The best solution is

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

Environment variable for "ng" may not be created. We can create it manually using the following steps:

Check if "ng" alias is present by opening your bash profile

touch ~/.bash_profile; open ~/.bash_profile

If there is no alias for "ng" found, Add the following alias in the bash file and save it

alias ng=/usr/local/Cellar/node/13.5.0/lib/node_modules/@angular/cli/bin/ng

Note: @angular/cli was installed under the following path for me /usr/local/Cellar/node/13.5.0/lib/node_modules/@angular/cli. So I have added ng which is present under angular cli to the alias.

Now, check the ng version using

ng --version

This worked for me.


After days of googling and getting no help neither on here nor from @Angular github which is pretty much useless, was finally able to resolve the issue and get my angular ng command not found issue resolved following these steps:

1. Instal nvm

Issue these 3 commands to install nvm. (Angular documented steps https://angular.io/guide/setup-local to setup your environment did not work for me).

So I installed nvm like so:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

export NVM_DIR="/Users/your-user-name/.nvm"

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

After this, make sure you restart terminal and you should be able to issue nvm --version to see version of installed nvm.

2. Install node using nvm

nvm install stable

nvm install node

3. Finally, install angular

npm install -g @angular/cli

4. Restart terminal

Restart terminal and you should be able to use ng version to see version installed on your system

 ~~ ng version


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 8.3.6
Node: 12.11.1
OS: darwin x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.803.6
@angular-devkit/core         8.3.6
@angular-devkit/schematics   8.3.6
@schematics/angular          8.3.6
@schematics/update           0.803.6
rxjs                         6.4.0

I can now create and start my project

ng new my-test-project

ng serve my-test project

enter image description here

I think SO should start getting serious about people down-voting questions or marking them as duplicates before reading them and even trying to understand what was asked and what the problem is.

It seems to be lots of people read the title and decide the fate of question just based on that and any disagreement ends up in blocking question entirely.

So much bias and hate on a site that is supposed to help.

Better alternatives are very much needed.

UPDATE

If you are like me and switched to use zsh shel instead of bash shell (since Catalina MacOs now uses zsh), you might have noticed that ng version has stopped working for you.

In that case, modify your .zshrc file by opening it in vim:

vi ~/.zshrc

In there, find this line:

source $ZSH/oh-my-zsh.sh

Underneath this line, add following line:

source /Users/Your-User-Name/.bash_profile

Save the file by hitting Esc key and typing :wq and hitting Enter

Restart your terminal

Reissue ng version and you should see it in your zsh shell:

enter image description here


If all the above methods doesn't work, then install angular-cli with Homebrew.

Run this in your Terminal (ZSH):

brew install angular-cli

Have a coffee, comeback and run this to test.

ng --version

Bingo.