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 08:02

if you have npm, install run the command

npm install -g @angular/cli

then bind your ng using this:

cd

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

Follow the Pictures for more help.

enter image description here enter image description here enter image description here enter image description here

查看更多
老娘就宠你
3楼-- · 2020-05-30 08:02

In my case

OS Version: Ubuntu 18.04.4 LTS

Node version v12.16.0

Remove ng from /usr/local/bin by using below command.

sudo rm -r ng

After that, installed ng by using command mentioned below.

sudo npm install -g @angular/cli

查看更多
霸刀☆藐视天下
4楼-- · 2020-05-30 08:03

I tried this and everything worked by changing the npm directory.

         mkdir ~/.npm-global
         npm config set prefix '~/.npm-global'
         export PATH=~/.npm-global/bin:$PATH
         source ~/.profile
         npm install -g jshint
         ng --version
查看更多
The star\"
5楼-- · 2020-05-30 08:03
>> npm uninstall -g angular-cli
>> npm uninstall -g @angular/cli

>> npm cache clean

Restart you machine

then >> npm install -g @angular/cli@latest

set Path : C:\Users\admin\AppData\Roaming\npm\node_modules@angular\cli

Hope you never get 'ng' not found

查看更多
爷的心禁止访问
6楼-- · 2020-05-30 08:05

The error may occur if the NodeJs is installed incorrectly. The proper way to fix that is to reinstall it properly, but if you're searching for a quick solution, you can try to install Angular CLI globally with sudo:

sudo npm install -g @angular/cli
查看更多
在下西门庆
7楼-- · 2020-05-30 08:06

I had a lot of issues installing it on a mac with all the permission errors Finally the following line solve the issue.

sudo npm i -g @angular/cli

查看更多
登录 后发表回答