Angular - ng: command not found

2020-05-30 07:35发布

I am 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.

标签: angular
20条回答
放我归山
2楼-- · 2020-05-30 07:46

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.

查看更多
Fickle 薄情
3楼-- · 2020-05-30 07:47

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

查看更多
Fickle 薄情
4楼-- · 2020-05-30 07:47

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

npm install -g npx
npx ng serve
查看更多
Root(大扎)
5楼-- · 2020-05-30 07:49

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

查看更多
Juvenile、少年°
6楼-- · 2020-05-30 07:51

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

查看更多
女痞
7楼-- · 2020-05-30 07:51

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

查看更多
登录 后发表回答