在Mac OS上找不到Angular CLI ng命令 [英] Angular CLI ng command not found on Mac Os

查看:143
本文介绍了在Mac OS上找不到Angular CLI ng命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此处查看了有关此问题的大量文章,并尝试了这些文章,但没有成功解决这个问题.

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

我使用的是MacOS,这是到目前为止,根据我在这里找到的建议,我已经做过的事情,但仍然出现此错误

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

这将输出:

/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

,其输出如下:

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

,但ng版本仍然无法正常工作:

, but ng version is still not working:

 ~~ ng version

-bash: ng: command not found

许多帖子建议应该在我的/Users/dinob目录下创建一个目录.npm-global,但我没有看到它.我只能看到.npm目录,而不是.npm-global.

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.

我还尝试了以下操作:

如上所述卸载角钢

酿造更新

brew升级节点////已从11.10.0升级到12.10.0

brew upgrade node // this upgraded from 11.10.0 to 12.10.0

然后重复上述步骤以安装angular/cli

then repeat steps above to install angular/cli

还是同样的问题,找不到ng命令

still same problem, ng command not found

这不是肯怀特(KenWhite)建议的重复问题,我已经查看了所有关于此问题的帖子(可以找到(以及更多)),尝试了这些帖子,但没有一个帖子能为我解决问题.

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命令已完成,并返回以下路径,但其中没有@angular目录:

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 

上面,没有bin文件夹:

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/

与该位置相同> @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/

推荐答案

经过数天的搜索并且在这里和@Angular github上都没有帮助,这几乎没有用,终于能够解决问题并得到我的帮助.通过以下步骤解决了ng命令找不到问题:

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.安装nvm

发出这3条命令以安装nvm. (Angular文档中的步骤 https://angular.io/guide/setup-local 可以设置您的环境不适用于我).

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).

所以我像这样安装了nvm:

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"

此后,请确保重新启动终端,并且应该能够发出nvm --version来查看已安装的nvm的版本.

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

2.使用nvm安装节点

nvm install stable

nvm install node

3.最后,安装angular

npm install -g @angular/cli

4.重新启动终端

重新启动终端,您应该可以使用ng version查看系统上安装的版本

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

我认为SO应该开始认真对待人们拒绝投票的问题或将其标记为重复项,然后再阅读它们,甚至试图理解所问的内容和问题所在.

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.

非常需要更好的选择.

更新

如果您像我一样,并改用zsh shel代替bash shell(因为Catalina MacOs现在使用zsh),您可能已经注意到ng version已经停止为您工作.

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.

在这种情况下,请在vim中打开您的.zshrc文件:

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

vi ~/.zshrc

在此处找到此行:

source $ZSH/oh-my-zsh.sh

在此行下,添加以下行:

Underneath this line, add following line:

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

通过按Esc键并输入:wq并按Enter键来保存文件

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

重新启动终端

重新发出ng version,您应该在zsh shell中看到它:

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

这篇关于在Mac OS上找不到Angular CLI ng命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆