'Angular CLI ng command not found on Mac Os

I looked at the numerous posts on here regarding this issue and tried them but had no success resolving this.

I am on MacOS and here is what I have done so far based on recommendations I have found here but I still get this error

 ~~ sudo npm uninstall -g angular-cli

 ~~ sudo npm uninstall -g @angular/cli

 ~~ sudo npm cache clean --force

 ~~ sudo npm install -g @angular/cli

This outputs:

/usr/local/Cellar/node/11.10.0/bin/ng -> /usr/local/Cellar/node/11.10.0/lib/node_modules/@angular/cli/bin/ng

> @angular/[email protected] postinstall /usr/local/Cellar/node/11.10.0/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js

+ @angular/[email protected]
added 245 packages from 185 contributors in 8.784s

However, issuing command below does not work:

 ~~ ng version

-bash: ng: command not found

Some people suggesting linking so I tried that as well:

 ~~ sudo npm link @angular/cli

, which outputs following:

/Users/dinob/node_modules/@angular/cli -> /usr/local/Cellar/node/11.10.0/lib/node_modules/@angular/cli

, but ng version is still not working:

 ~~ ng version

-bash: ng: command not found

Many posts suggest that there should be a directory .npm-global created under my /Users/dinob directory but I dont see it. I aonly see .npm directory, not .npm-global.

I also tried following:

uninstall angular as described above

brew update

brew upgrade node // this upgraded from 11.10.0 to 12.10.0

then repeat steps above to install angular/cli

still same problem, ng command not found

This is not a duplicate question as KenWhite suggests and I have reviewed all the posts on SO I could find (and more) regarding this issue, tried them and none of them solved the issue for me.

sudo npm install -g @angular/cli command completed and returned following paths but none of them @angular directory in them:

/usr/local/Cellar/node/11.10.0/bin/ng -> /usr/local/Cellar/node/11.10.0/lib/node_modules/@angular/cli/bin/ng 

Above, there is no bin folder:

dinob @ /usr/local/Cellar/node/11.10.0 
 ~~ ls -la

total 80
drwxr-xr-x  8 dinob  staff    256  2 Oct 11:30 ./
drwxr-xr-x  5 dinob  staff    160 27 Sep 09:29 ../
-rw-r--r--@ 1 dinob  staff   8196  2 Oct 11:32 .DS_Store
-rw-r--r--  1 dinob  staff  26696 14 Feb  2019 README.md
drwxr-xr-x  3 dinob  staff     96 14 Feb  2019 etc/
drwxr-xr-x  3 dinob  staff     96 14 Feb  2019 include/
drwxr-xr-x  5 dinob  staff    160  2 Oct 11:22 lib/
drwxr-xr-x  5 dinob  staff    160 14 Feb  2019 share/

Same for this location > @angular/[email protected] postinstall /usr/local/Cellar/node/11.10.0/lib/node_modules/@angular/cli:

dinob @ /usr/local/Cellar/node/11.10.0/lib/node_modules 
 ~~ ls -la

total 16
drwxr-xr-x   6 dinob  staff   192  2 Oct 11:22 ./
drwxr-xr-x   5 dinob  staff   160  2 Oct 11:22 ../
-rw-r--r--@  1 dinob  staff  6148  2 Oct 11:27 .DS_Store
drwxr-xr-x   7 root   staff   224 26 Sep 16:42 n/
drwxr-xr-x  26 dinob  staff   832  2 Oct 11:28 npm/
drwxr-xr-x   6 dinob  staff   192 15 Jul 16:32 react-native-cli/


Solution 1:[1]

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.

Solution 2:[2]

The best solution is

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

Solution 3:[3]

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.

Solution 4:[4]

I had the same problem, but the solution was to just add to my $PATH. On MacOS Mojave with zsh, @Angular/CLI was not getting added to $PATH. You can add it to your path just by appending to /private/etc/paths:

  1. sudo vim /private/etc/paths
  2. append /Users/my_user_name/node_modules/@angular/cli/bin or wherever you installed @Angular/CLI.
  3. save (:wq) and restart shell.

ng version then works.

Solution 5:[5]

My terminal display zsh: command not found: ng ,in visconde terminal not found command ng and not Mac terminal, I saw that in bashrc there was a line with the export of the ng command, so I copied the export that was inside bash and pasted it into ˜/.zshrc and now it works!

Solution 6:[6]

This is what worked for me, to fix this error

~ ng --version
zsh: command not found: ng

fix:

export PATH="$HOME/.npm-global/bin:$PATH"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fransie
Solution 2 Mostafa Saadatnia
Solution 3
Solution 4 Tommy Sharkey
Solution 5 MiguelCPJava
Solution 6 Sebastian Castaldi