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:53

Removing NODE and using NVM instead fixed a lot of issues.

removing Node from your system

install NVM from here https://github.com/creationix/nvm

Install Node via NVM: nvm install

stable run npm install -g angular-cli

LINK

查看更多
家丑人穷心不美
3楼-- · 2020-05-30 07:55

You must know the full path of your angular installation. For example: C:\Users\\AppData\Roaming\npm\node_modules@angular\cli\bin\ng . Type in cmd, powershell or bash

alias ng="C:\Users\<your username>\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng"
查看更多
▲ chillily
4楼-- · 2020-05-30 07:56

*Windows only*

The clue is to arrange the entries in the path variable right.

As the NPM wiki tells us:

Because the installer puts C:\Program Files (x86)\nodejs before C:\Users\\AppData\Roaming\npm on your PATH, it will always use version of npm installed with node instead of the version of npm you installed using npm -g install npm@.

So your path variable will look something like:

…;C:\<path-to-node-installation>;%appdata%\npm;…

Now you have to possibilities:

  1. Swap the two entries so it will look like …;%appdata%\npm;C:\<path-to-node-installation>;… This will load the npm version installed with npm (and not with node) and with it the installed Agnular CLI version.

  2. If you (for whatever reason) like to use the npm version bundled with node, add the direct path to your global Angualr CLI version. After this your path variable should look like this: …;C:\Users\<username>\AppData\Roaming\npm\node_modules\@angular\cli;C:\<path-to-node-installation>;%appdata%\npm;… or …;%appdata%\npm\node_modules\@angular\cli;C:\<path-to-node-installation>;%appdata%\npm;… for the short form.

This worked for me since a while now.

查看更多
We Are One
5楼-- · 2020-05-30 07:57

mocOS: ng command does not link in /usr/local/bin. I fixed the problem by adding it.

ln -s /usr/local/Cellar/node/10.10.0/lib/node_modules/angular-cli/bin/ng /usr/local/bin/ng
查看更多
唯我独甜
6楼-- · 2020-05-30 08:00

I had that same problem and just solved it.

make sure you have node installed.

after running

npm i -g @angular/cli

when installation is finished, try re-opening your git bash or whatever you're using or open it in a new folder. boom. it worked for me

查看更多
该账号已被封号
7楼-- · 2020-05-30 08:02

If you have already installed @angular/cli

Then you only need to link it to npm using npm link @angular/cli

Otherwise first install angular by npm install @angular/cli and then link.

查看更多
登录 后发表回答