41

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/cli@8.3.6 postinstall /usr/local/Cellar/node/11.10.0/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js

+ @angular/cli@8.3.6
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/cli@8.3.6 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/
pixel
  • 9,653
  • 16
  • 82
  • 149
  • 2
    Possible duplicate of [When trying to install angular, ng command is not found](https://stackoverflow.com/questions/57808412/when-trying-to-install-angular-ng-command-is-not-found) and several others, easily found by searching this site for the exact error message `bash: ng: command not found`. – Ken White Sep 27 '19 at 16:42
  • @KenWhite as explained I searched and went over these posts already, it is not duplicate – pixel Sep 27 '19 at 16:51
  • check this out https://stackoverflow.com/a/71208671/6521821 it works for me. – Buddhi Hasanka Feb 21 '22 at 15:33
  • check this out https://stackoverflow.com/a/71208671/6521821 it works for me. – Buddhi Hasanka Feb 21 '22 at 15:34
  • `npm link @angular/cli` worked for me on MacOS monterey – tijko Nov 15 '22 at 20:34

7 Answers7

56

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

pixel
  • 9,653
  • 16
  • 82
  • 149
  • 2
    I agree 100%. You never know how someone will phrase a search nor how the results will come up. I am glad you answered this so well. – Steve Nov 18 '19 at 17:35
  • I also had a problem "autosolved" by following the instructions in the terminal: ```nvm is not compatible with the npm config "prefix" option: currently set to "/Users/solde/.npm-packages" Run `npm config delete prefix` or `nvm use --delete-prefix v13.3.0` to unset it.``` – Soldeplata Saketos Dec 17 '19 at 18:45
  • 1
    +1 for the Update. This was exactly the situation I was in after changing my Mac terminal to zsh. This was what I needed and it appears everything is fixed. Thanks! – LeftOnTheMoon Dec 31 '19 at 00:01
  • This helped me out after upgrading my storage on my MacBook Pro and running Big Sur. Though, I will not criticize GitHub because that repository and forum came through for me many-a-day ... – Janou Jan 20 '21 at 01:19
  • @pixel You deserve a medal. – NoughT Jan 30 '22 at 17:15
32

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.

fransie
  • 67
  • 8
Arjun Kesava
  • 740
  • 1
  • 10
  • 14
  • 5
    For me it was `brew install angular-cli` – Vladtn Jun 11 '20 at 07:44
  • It worked, i created a alias using above command, Remove that alias and then try it out, it should work perfectly fine – Arpan Saini Jun 27 '21 at 01:15
  • 1
    A nice cup of coffee later and everything is working, thanks! – Tim Brunsmo Apr 15 '22 at 11:54
  • 1
    This is the the sixth time I'm coming to this post to deal with the issue, and every time I stopped at the first marked answer, and never got it solved. Today I decided to scroll down and see what others say, and yes bingo, this answer works ! I got my ng command back again. Was a kinda frustrating issue. Thanks @Arjun – Himmels DJ Jun 02 '22 at 16:11
8

The best solution is

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

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"
Sebastian Castaldi
  • 8,580
  • 3
  • 32
  • 24
2

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.

smnth90
  • 750
  • 5
  • 14
1

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.

Tommy Sharkey
  • 21
  • 1
  • 3
0

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!

MiguelCPJava
  • 53
  • 1
  • 2
  • 7