134

I'm 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.

Tony Brasunas
  • 4,012
  • 3
  • 39
  • 51
Frank
  • 1,383
  • 2
  • 9
  • 6
  • Version of npm? node? what operating system do you use? All those relate to this problem. Please update your question – Jota.Toledo Oct 08 '17 at 08:55
  • 2
    Have you checked this one https://stackoverflow.com/questions/37227794/ng-command-not-found-while-creating-new-project-using-angular-cli – Asad Shakeel Jul 05 '19 at 12:24
  • *As an aside:* if you work on multiple projects using different versions of the CLI (so that always running a single global version is not an option), try `export PATH=$PATH:node_modules/@angular/cli/bin/ng` - it will pick the local version (relative to the current directory), as long as you run the `ng` command from within the root directory of your Angular (sub)project. – Janaka Bandara Dec 13 '19 at 13:57

31 Answers31

123

Guess You are running on Windows (To make @jowey's answer more straightforward).

  • Install Angular normally from your bash $ npm install -g @angular/cli@latest Next is to rearrange the PATHS to
  • NPM
  • Nodejs
  • Angular CLI

in System Environment Variables, the picture below shows the arrangement.

enter image description here

naveen
  • 53,448
  • 46
  • 161
  • 251
Adedoyin Akande
  • 2,266
  • 1
  • 19
  • 21
  • 10
    Thanks, I just needed to add:C:\Users\"MY-USERNAME-HERE"\AppData\Roaming\npm – JoanR Nov 30 '18 at 11:08
  • 1
    @Adedoyin: what exactly do you need to find in your path ending with @angular/cli? ng binary is located inside of bin/ (or in the folder specified at the next line). – Fabien Haddadi Aug 22 '19 at 01:32
  • 1
    ´npm ls´ lists the local repository and ´npm ls --global´ lists the global repository. The path to the repository is printed out in the first line. Add both just to be sure – bachph Oct 16 '19 at 15:50
  • 1
    I had to add the bin folder of angular CLI to the path `\AppData\Roaming\npm\node_modules\@angular\cli\bin` – Raul Nov 16 '20 at 17:37
  • 1
    Thanks for the solution, I took 2-3 week to find the solution until find yours. – Manuel Lucas Mar 26 '21 at 15:26
  • this is still valid, it worked for me – Ricardo Pontual Nov 07 '22 at 10:55
63

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

hajisky
  • 673
  • 6
  • 7
45

The error may occur if the NodeJs is installed incorrectly or not installed at all. The proper way to fix that is to install/reinstall it the right way (check their official website for that), but if you're searching for a quick solution, you can try to install Angular CLI globally:

npm install -g @angular/cli

If it doesn't work and you are in a hurry, use sudo:

sudo npm install -g @angular/cli

Don't forget to reopen your terminal window.

P.S.
  • 15,970
  • 14
  • 62
  • 86
  • doesn't work. even if installed with sudo, the ng command is still not found. the $PATH isn't updated at all. – Nexus Apr 22 '18 at 23:08
  • 6
    If you need sudo for npm you have an improper installation of npm. – Bon Jul 05 '19 at 21:32
  • 1
    @Bon, you're totally right! Installation with `sudo` is just a quick fix – P.S. Jul 06 '19 at 10:52
  • All I had to do was to uninstall the existing nodejs and reinstall it from the nodejs website. The one from my computer was from the corporate approved software. – Auguste Aug 19 '19 at 18:59
12

For MacOS

Sometimes the ng command does not get established as a link in /usr/local/bin. I fixed the problem by adding it manually:

ln -s /usr/local/Cellar/node/10.10.0/lib/node_modules/angular-cli/bin/ng /usr/local/bin/ng
Tony Brasunas
  • 4,012
  • 3
  • 39
  • 51
zhai
  • 181
  • 3
  • 5
  • 2
    Thank you. Your solution works. My ng path is `/usr/local/Cellar/node/11.6.0/lib/node_modules/@angular/cli/bin/ng` – Chang Jan 04 '19 at 10:46
  • Worked for me too. My ng path with Node 12 and Angular 11 turned out to be: `/usr/local/Cellar/node/12.12.0/lib/node_modules/@angular/cli/bin/ng` – Tony Brasunas Dec 24 '20 at 20:21
10

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.

Asad Shakeel
  • 1,949
  • 1
  • 23
  • 29
8

It may has not helped OP, but it solved my problem. This answer is to help others who have not tried the command mentioned in OP's question.

Just use npm install -g @angular/cli@latest. It did the trick for me.

IonicMan
  • 743
  • 1
  • 12
  • 31
6

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

6

I had the same issue in Windows. I could solve it by running the ng command with npm

ng g c test

Error : C:\Users\user\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found

Solution :

$ npm run ng g c test

Other solution worked for me to use Windows PowerShell or command prompt instead of bash shell

jfk
  • 4,335
  • 34
  • 27
5

*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<username>\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.

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

naveen
  • 53,448
  • 46
  • 161
  • 251
jowey
  • 7,581
  • 6
  • 27
  • 46
5

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

Mohamad Mousheimish
  • 1,641
  • 3
  • 16
  • 48
steve
  • 257
  • 4
  • 12
5

Windows 10 Only

If you are using Git Bash and also you are sure that you have done all steps that are listed above, still getting an error like this, run following command:

alias ng="C:/Users/<your-username>/AppData/Roaming/npm/node_modules/@angular/cli/bin/ng"

then run ng -v

Finally, it works if you see the version of Angular-CLI

John Valdetine
  • 416
  • 2
  • 9
  • 26
5

Most of the time developers install just Node.js and start working on development. This issue related angular cli dependency on your development environment.

You can fix this with command

npm install -g @angular/cli
Muhammad Hamed K
  • 279
  • 1
  • 4
  • 9
5
  • First of all check by running npm config get prefix
  • It should return some thing like (C:\Users\acer\AppData\Roaming\npm)
  • if it does not return it.
  • run npm config delete prefix
  • then run npm install -g @angular/cli@latest
  • And check by running ng --version
  • It has solved my problem. Hope it will help you.

**

  • on linux npm get prefix gives /usr/local, the ng executable is at /usr/local/bin/ng and is a symbolic link to ../lib/node_modules/@angular/cli/bin/ng.js – Cie6ohpa Sep 23 '22 at 04:14
4

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

Mohamad Mousheimish
  • 1,641
  • 3
  • 16
  • 48
Yogesh Kumar
  • 1,016
  • 11
  • 10
4

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.

3

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

  • It worked for me on a mac environment as a quick workaround. However, I need to run the commands every time with a new terminal window. – Homa Mar 24 '22 at 12:44
2

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

Community
  • 1
  • 1
Rahul Singh
  • 19,030
  • 11
  • 64
  • 86
  • 2
    If you are using nvm and have more than one version of node installed, make sure you are using the same version of node that you used when you installed Angular. I keep forgetting this. – John Velonis Apr 27 '20 at 15:50
1

Step 1 : Delete "npm" folder from the following path

C:\Users\YourUserName\AppData\Roaming

Step 2 : Once you have the "npm" folder deleted, uninstall Node.Js.

Step 3 : Reinstall Node.JS

Step 4 : Install Angular CLI Using this command npm install -g @angular/cli@latest

Step 5: Now try : ng --version or ng -v

Jitendra Suthar
  • 2,111
  • 2
  • 16
  • 22
1

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

AceMati
  • 19
  • 2
  • This downloaded the missing components for me and then the gradle wrapper downgraded to the correct version for the project. – G_V Jul 05 '19 at 08:28
1

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

npm install -g npx
npx ng serve
kat
  • 577
  • 4
  • 7
1
>> 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

1

I'll add this as "yet another option" which worked for me when none of the other options worked( on windows ).

You can run the angular binary via its full path name. node C:\Users\user\node_modules@angular\cli\bin\ng.js --version

Oddly enough, adding these paths to my env didn't work...for some reason windows opened editor to edit ng.js file instead of running it.

Rainer Plumer
  • 3,693
  • 2
  • 24
  • 42
0

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
eyesun
  • 13
  • 6
0

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"
Petar Gutov
  • 67
  • 1
  • 3
0

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

Muhammad Sulman
  • 1,611
  • 1
  • 19
  • 25
0

For Linux user

$ alias ng="/home/jones/node_modules/@angular/cli/bin/ng"

then check angular/cli version

ng --version

enter image description here

0

alias ng="C:/Users/<user_name>/AppData/Roaming/npm/node_modules/@angular/cli/bin/ng".. This did work..

Happy Coding :)

Ganga
  • 11
  • 2
  • 2
    Please do not say thanks (by copying a different answer, e.g. the one by Petar Gutov, not even if you slightly change it to not being character by character identical). On StackOverflow saying thanks is by upvoting - once you have the privilege for that. – Yunnosch May 01 '21 at 08:24
0

I guess everyone figured this out years ago but me. simple ng stopped working when I updated node. I tried all the previous suggestions in this thread to no avail but this is my solution. the command npm ng works but darn it I want just ng to work. So I created a bat filed named ng.bat with this content

npm ng %*

either put ng.bat in a directory recognized by path or add a new path in This Computer / Properties / Advanced System Settings / Environment Variables/ System Variables / Path . For instance I added C:\Shortcuts to path.

EDIT the above answer is not THE REAL SOLUTION. What npm need is to find the npm-cli.js which is located in the npm bin directory. If a path is not set to bin then not work. I just copied npm-cli.js and put it in the npm directoy which has a path set to it.

FairSite2C
  • 81
  • 3
  • 7
0

Windows oriented:

If you're chasing an "update node/angular and I wiped my AppData folder and now the world hates me stream of errors", then this may help.

Clear out Environment Variable settings for Node/npm/@angular/cli (They don't help)

Install Node.JS/npm from https://nodejs.org/en/ (Remember where you install it)

Confirm the location npm is [currently] running from:

npm config get prefix

Realize that is not where you just install new/fresh Node.

Update npm global pointer (which is not an environment variable)

npm config set prefix "C:\Program Files\nodejs"

Reinstall Angular

npm install -g @angular/cli@latest

Check angular install

ng --version

Hopefully this helps someone. Sorry, you'll have to reinstall any other interesting packages.

Lodlaiden
  • 361
  • 1
  • 10
0

For me the issue was something with node. Version was very wrong somehow.

Uninstalled node from "Add or remove programs" and then re-installed it using the file from their website.

-6

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