198

Installed angular-cli globally using (npm install -g angular-cli) but when I'm trying to create project using ng new my-project it is throwing error:

ng: command not found

mruanova
  • 6,351
  • 6
  • 37
  • 55
lego
  • 2,081
  • 2
  • 10
  • 4
  • what happens when you type ng --help? This was also posted on angular cli repository. check this [link](https://github.com/angular/angular-cli/issues/503) – VirendraJ May 15 '16 at 06:02
  • Even when I type ng --help same issue ng: command not found, in issue log there are suggesting to use nvm but I would like to use npm. I tried to correct the path by adding alias in my .profile but already proxy settings are there, so how can I add new path using alias = alias ng="Users/xxxx/npm/lib/node_modules/angular-cli/bin/ng" – lego May 15 '16 at 07:24
  • Can you post your os version as well as your npm version – pd farhad May 16 '16 at 04:16
  • Using Mac os, npm version - 2.14.20 & node version - 4.4.0 – lego May 16 '16 at 04:29
  • 5
    Can you verify it is intalled via... `npm ls --global --depth 0` – Brocco May 16 '16 at 19:36
  • yes i installed globally, solution to fix this issue is to set path of ng in .profile but now I am getting new error as (node:25315) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version. /Users/pkodiya/node_modules/configstore/index.js:54 throw err; ^ Error: EACCES: permission denied, open '/Users/pkodiya/.config/configstore/ember-cli.json' You don't have access to this file. – lego May 16 '16 at 21:57
  • @lego take a look at this comment it will point you in the right direction to get past that error... https://github.com/angular/angular-cli/issues/345#issuecomment-201276673 – Brocco May 18 '16 at 01:29
  • I am facing the same problem – Aniruddha Das Oct 18 '16 at 22:08
  • try to uninstall your node and install node version 8.10.0. – Cyan Baltazar May 02 '18 at 02:25

42 Answers42

307

The issue is simple, npm doesn't know about ng

Just run npm link @angular/cli and it should work seamlessly.

abhinavroy23
  • 3,630
  • 1
  • 14
  • 19
67

First, angular-cli is deprecated and has been replaced with @angular/cli. So if you uninstall your existing angular-cli with npm uninstall angular-cli, then reinstall the package with the new name @angular/cli you might get some conflicts. My story on Windows 7 is:

I had installed angular-cli and reinstalled using npm install -g @angular/cli, but after doing some config changes to command-line tools, I started getting the ng command not found issue. I spent several hours trying to fix this but none of the above issues alone worked. I was able to fix it using these steps:

Install Rapid Environment Editor and remove any PATH entries for node, npm, angular-cli or @angular/cli. Node.js will be in your System path, npm and angular entries are in the User path.

Uninstall node.js and reinstall the current version (for me 6.11.1). Run Rapid Environment Editor again and make sure node.js and npm are in your System or User path. Uninstall any existing ng versions with:

npm uninstall -g angular-cli

npm uninstall -g @angular/cli

npm cache clean

Delete the C:\Users\%YOU%\AppData\Roaming\npm\node_modules\@angular folder.

Reboot, then, finally, run:

npm install -g @angular/cli

Then hold your breath and run:

ng -v

If you're lucky, you'll get some love. Hold your breath henceforward every time you run the ng command, because 'command not found' has magically reappeared for me several times after ng was running fine and I thought the problem was solved.

Shanu Gupta
  • 3,699
  • 2
  • 19
  • 29
VanAlbert
  • 2,299
  • 1
  • 21
  • 17
  • 4
    sudo npm install -g @angular/cli – Mohammad Suhel Shaikh Aug 15 '18 at 02:49
  • Sorry but this is not working. I tried all the commands above and I used sudo to issue them. I am on mac OS. – pixel Sep 27 '19 at 14:46
  • I followed this format and it worked fine for me without the Rapid Environment Editor. In Windows 10 I manually updated the Paths in the Einvronment Variables. I hadn't run Node or Angular in a while as my last project was dotnet core. So I had to reinstall latest of both npm and node, then reset my paths and reboot before angular/cli uninstall step. – Vic May 03 '20 at 19:28
  • 2
    if "ng -v" does not work try "ng version". This seems to be the command for version check with cli 14 – Deshan Jun 23 '22 at 17:17
  • hey why does at my end in windows terminal `ng -v` doesn't work but `ng v` works – humbleCodes Jun 22 '23 at 17:10
  • @Deshan yes that is it, I spent 3 hours repeating same stuff and tweaking path variables but in the end the problem is `ng -v` command itself – humbleCodes Jun 22 '23 at 17:12
33

Make sure that the npm directory is in your "Path" variable.

If the module is installed properly, it may work if you start it out of your global node module directory, but your command line tool doesn't know where to find the ng command when you are not in this directory.

For Win system variable add something like:

%USERPROFILE%\AppData\Roaming\npm

And if you use a unix-like terminal (emulator):

PATH=$PATH:[path_to_your_user_profile]/path-to-npm
fuma
  • 5,067
  • 4
  • 35
  • 39
  • 2
    If you work on multiple projects using different versions of the CLI (so that always running the single global version is not an option), try `export PATH=$PATH:node_modules/@angular/cli/bin/ng` - it will pick the local version, as long as you run the `ng` command within the root directory of your Angular (sub)project. – Janaka Bandara Dec 13 '19 at 13:56
  • @JanakaBandara how would I add that export command in Win10? Is it ok to add it in the .bash_profile? – Diego Ortiz Feb 19 '20 at 19:05
  • 1
    Yup, I usually add that to `.bashrc` – Janaka Bandara Feb 20 '20 at 07:00
  • 1
    After doing this make sure you uninstall and reinstall any packages that you installed while it was missing. There's a good chance that their installations are corrupted with a lot of missing dependencies. I did a fresh install of node v14.17 and npm and wasn't expecting the node installer to fail to add npm to the path. It added nodejs without a problem. If npm is missing from your path you'll need to reinstall any packages that you installed prior to adding it to the path. That was my problem with the angular cli. I was looking at angular cli as the problem but npm was the real problem – m12lrpv Jun 09 '21 at 23:25
27

the easiest solution is (If you have already installed angular) :

1 remove the ng alias if existing

unalias ng

2 add the correct alias

alias ng="/Users/<user_name>/.npm-global/bin/ng"

3 run ng serve for example and it will work.

Achref Gassoumi
  • 1,035
  • 10
  • 20
  • there is no .npm-global directory on Mac – pixel Sep 27 '19 at 14:47
  • @pixel for sure there is an npm-global on mac please reference here for further details https://flaviocopes.com/npm-packages-local-global/ – Achref Gassoumi Oct 07 '19 at 13:40
  • 1
    @AchrefGassoumi Thanks but after googling for hours, no location suggesting aliasing to a location would not work. The only way for me to resolve this was do use nvm as I explained in my answer to this question https://stackoverflow.com/questions/58138138/angular-cli-ng-command-not-found-on-mac-os?noredirect=1#comment102663475_58138138 – pixel Oct 07 '19 at 15:21
21

This is how I made it worked for me :).

1 - npm link @angular/cli

It will return you the path of cli, which will look like this

/usr/local/Cellar/node/11.3.0_1/lib/node_modules/@angular/cli

For this part, /11.3.0_1 please replace this with your respective node version that can be found by typing node --version

2 - cd ~/

3 - open .bash_profile

In the bash profile create an alias for cli like this,

alias ng="/usr/local/Cellar/node/11.3.0_1/lib/node_modules/@angular/cli/bin/ng"

4 - source ~/.bash_profile

This is how your .bash_profile will look like once you add alias to it.

enter image description here

Now typing ng in the terminal will display output shown in attached snapshot.

enter image description here

I hope this answer will be helpful.

Divyanshu Rawat
  • 4,421
  • 2
  • 37
  • 53
17

For Mac run

npm install -g @angular/cli@latest

then run

alias ng="/usr/local/lib/node_modules/node/lib/node_modules/@angular/cli/bin/ng"

Check if working

ng version
Francesco
  • 594
  • 7
  • 14
16

In my case install angular cli

npm install -g @angular/cli@latest

update Nodejs to latest, then all should work fine.

...and if you 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...

Ali Jamal
  • 619
  • 7
  • 12
15

Run below commands:

npm uninstall -g angular-cli

npm uninstall -g @angular/cli

npm cache clean

npm install -g @angular/cli@latest

alias ng="C:/Users/itaas/.npm-global/ng" ( Location of ng file in npm folder)

And finally run :

ng -v 

Ng-v

Shanu Gupta
  • 3,699
  • 2
  • 19
  • 29
Gajender Singh
  • 1,285
  • 14
  • 13
15

If you have installed angular cli globally but ng isn't working, just do this:

echo -e "export PATH=$(npm prefix -g)/bin:$PATH" >> ~/.bashrc

source ~/.bashrc

ng --version
faye.babacar78
  • 774
  • 7
  • 12
  • C:\>echo -e "export PATH=$(npm prefix -g)/bin:$PATH" >> ~/.bashrc The system cannot find the path specified. – GregJF Feb 16 '20 at 21:23
  • This command is only for Unix/Linux users. If you're on Windows, The Angular CLI should be install in administrator mode. – faye.babacar78 Feb 16 '20 at 23:05
14

I've solved the same issue with adding an alias like:

alias ng="path-to-your-global-node-modules/angular-cli/bin/ng"
Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
m.zemlyanoi
  • 335
  • 1
  • 5
  • 15
  • 1
    This worked fine for me, but every time when I login I had to do it, so I added it in my .bashrc file in this way: "nano ~/.bashrc" and then added following line there: alias ng="/usr/local/lib/node_modules/@angular/cli/bin/ng" I am running ubuntu 14.04 on vagrant – Sabeeh Chaudhry Nov 02 '17 at 14:25
11

I was facing same issue, I was using git bash terminal, I installed angular cli using this command

npm install -g @angular/cli

but when I try to create new app it was giving me error ng: command not found, I just restarted my pc and it worked, even closing and opening terminal again will also fix issue sometimes

Al Fahad
  • 2,378
  • 5
  • 28
  • 37
8

Adding %AppData%\npm to the Win path have worked for me.

Source : https://github.com/angular/angular-cli/issues/1183 , the first comment.

gatsby
  • 1,148
  • 11
  • 12
5

Same problem here running Windows 10 x64 / NodeJS 6.9.1 / npm 3.10.9.
After installation of Angular CLI via npm:

'ng' command cannot be found

Do the following:

  1. Uninstalled npm with npm uninstall -g npm
  2. Uninstalled NodeJS via control panel / programs and features
  3. Downloaded and ran 'old' NodeJS installer release 6.5.0 from https://nodejs.org/download/release/v6.5.0/ (node-v6.5.0-x64.msi).
  4. After NodeJS 6.5.0 installation completed, open powershell and npm install -g angular-cli
  5. Grab quick coffee
  6. After installation completed, ng worked OK.

HTH

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
Matt Kane
  • 171
  • 2
  • 6
5

Make sure angular-cli is installed before trying to create a project. Windows users can install angular-cli without giving permission to command but MAC users have to use sudo before executing the command as follow:

sudo npm install -g angular-cli

Type a password when asked and press enter to proceed.

Maihan Nijat
  • 9,054
  • 11
  • 62
  • 110
5

First of all, check if your npm and node installed properly
with commands npm version and node -v.

If they are proper:

  1. Find the root global Directory of NPM npm root -g (it will give you root of your global npm store)

  2. Uninstall old angular cli with npm uninstall -g angular-cli and npm cache clean

  3. Reinstall new Version of angular npm install -g @angular/cli@latest

  4. make an Alias of Name ng:

alias ng="C:/ProgramData/npm/node_modules/@angular/cli/bin/ng"

alias ng="<ath-to-your-global-node-modules>/<angular cli path till ng>"
(from answered Oct 20 '16 at 15:30 @m.zemlyanoi )

then to check you can type ng -v

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
5

For Mac users:

1) Install @angular/cli globally

$ sudo npm install -g @angular/cli
/usr/local/Cellar/node/10.0.0/bin/ng -> /usr/local/Cellar/node/10.0.0/lib/node_modules/@angular/cli/bin/ng

2) Create alias for ng

alias ng="/usr/local/Cellar/node/10.0.0/lib/node_modules/@angular/cli/bin/ng"

Done

Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68
5

try this :

alias ng="~/node_modules/@angular/cli/bin/ng"

Ali
  • 664
  • 3
  • 13
  • 21
4

For mackBook OS

sudo npm uninstall -g @angular/cli
sudo npm cache verify
sudo npm install -g @angular/cli@latest

try with ng -v if not work then set alias and try

alias ng="/usr/local/Cellar/node/10.0.0/lib/node_modules/@angular/cli/bin/ng"
abhinavsinghvirsen
  • 1,853
  • 16
  • 25
3

if you find this error when you are installing angular-cli, -bash: ng: command not found try this it works,

After 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
Gaurav Gandhi
  • 3,041
  • 2
  • 27
  • 40
2

Do you install the node js package? https://nodejs.org/en/ Regards

2

According to npm, the angular-cli has been renamed to @angular/cli you can use the following syntax to install it.

npm install -g @angular/cli
nPcomp
  • 8,637
  • 2
  • 54
  • 49
2

If you are using asdf-vm you need run adsf reshim nodejs to recreate links with global modules.

In my case this resolve my problem, I hope resolve to you all too.

Clairton Luz
  • 2,116
  • 19
  • 15
2

Most likely the problem is that you are using PowerShell and not the command line. If you use Windows PowerShell run:

cmd

then next try:

ng --version

if it works run:

ng new my-project
1

soluton for windows operating system only....... first step:

install nodejs version: nodev 8.1.2

second step: set up environment variable like: C:\ProgramFiles\nodejs

Third step: install angular use this command: npm install -g @angular/cli

after installation whereever you have to create project like: ng new first-project......

raja manikkam
  • 91
  • 1
  • 1
1

For me (on MacOSX) I had to do:

nvm install stable
npm install -g angular-cli

This installed ng into:

/usr/local/lib/node_modules/@angular/cli/bin/ng

But npm did not put a link to ng into

/usr/local/bin/

Which was why it was not part of the %PATH and therefore available from the command line except via an absolute address.

So I used the following the create a link to ng:

sudo ln -sf /usr/local/lib/node_modules/\@angular/cli/bin/ng /usr/local/bin/ng
Justin.Cooke
  • 387
  • 2
  • 15
1

This worked for me:

  1. Go to C:\Users{{users}}\AppData\Roaming and delete the npm folder
  2. Uninstall node and install it again
  3. Run the command to install angular cli

    npm install -g @angular/cli
    
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
PrJ
  • 53
  • 8
1

running

export PATH=$PATH:/c/Users/myusername/AppData/Roaming/npm 

helped.

Make sure your actual username is in the myusername section

Fey Agape
  • 181
  • 1
  • 5
1

Repairing NodeJS installation on windows resolved it for me.

Glance
  • 108
  • 5
  • Yesterday my problem was fixed by doing an npm update, but today THIS fixed my problem today. I wonder what tomorrow's will be. I dont understand why this keeps 'breaking' – Marvin Zumbado Sep 07 '21 at 19:00
1

I came here because I had the same issue on windows. The thing that baffled me most on this was I have had Node installed since Angular 4 dabbling here and there. And sure enough. That was my problem. I needed to upgrade node.

Just installing the newest version worked fine for me without having to do any of the above steps post the new install

Callat
  • 2,928
  • 5
  • 30
  • 47
1

Maximum time, this is a path issue conflict between npm and angular cli.

The solution that worked for me ->

  1. %USERPROFILE%\AppData\Roaming Paste this in File Explorer and delete npm folder.
  2. npm install -g @angular/cli@latest run this command to reinstall latest angular cli.
  3. npm link @angular/cli now this command can solve your path issue

Literally that three steps will fix your issue, otherwise you need to update environment variable by search and open Edit the system environment variables

Ariful Ahsan https://arifulahsan.com

Ariful Ahsan
  • 91
  • 1
  • 5
0

If you are working in windows 7 and you can not run command start with ng

please, update the angular/CLI at once and try to use ng commands

use below comman to update latest CLI

npm install -g @angular/cli@latest
Hardik Leuwa
  • 3,282
  • 3
  • 14
  • 28
0

This works to update your angular/cli //*Global package (cmd as administrator)

npm uninstall -g @angular/cli
npm cache verify
npm install -g @angular/cli@latest
alvic
  • 288
  • 2
  • 5
0

Firstly install '@angular/cli' by using npm as global module

sudo npm install -g @angular/cli

After that try to ping the cli by using 'ng' command from the terminal window.If any problem like

Command 'ng' not found

Then you need to manually setup the

ng

command availability.You set this step by running the following command.

ln -s path-to-your-ng-command /bin

eg:

sudo ln -s /opt/node/lib/node_modules/@angular/cli/bin/ng /bin/

0

In my case, it was happening when I restarted working on an adjacent tab. It was the npm which was not set. Please check the version of npm wither using

npm -v

or if you are having nvm then

nvm list

or

nvm current

I set it to 8.9.1 and then it started working again. I hope it helps.

Rahul
  • 1,070
  • 3
  • 21
  • 47
0

In my case, I was simply running the wrong node version.

I had just previously installed a new node version to play around with Angular (2). At work we use 6.x so that is my default in nvm. After restarting the laptop ng stopped working simply because I was running node 6.x again. So for me it was simply a matter of using the version with which I was installing the Angular CLI:

nvm use node // with the node alias pointing to the right version

or

nvm use v8.11.3 // if you happen to know the version

Check your installed versions and aliases with

nvm list 
Flip
  • 6,233
  • 7
  • 46
  • 75
0

If you have a MacOS computer (mine is MOJAVE 10.14.2), just add these lines to the end of your ~/.bash_profile file:

export ANGULAR=~/.nvm/versions/node/v10.8.0/bin/ng
export PATH=$ANGULAR:$PATH

Notice that v10.8.0 is the version of my installed Node.js. To get which version is yours, run this:

node --version

When done, reload it via your terminal/bash:

cd ~
source .bash_profile

After doing these steps you should be able to run your ng binary file.

Marcelo Gumiero
  • 1,849
  • 2
  • 14
  • 14
0

If you have zsh installed add alias to .zshrc file in home directory as well.

RasenKoD
  • 21
  • 2
0

If you use enterprise computer and unable to access system environments

use RapidEE to edit user variables then add to path these

%AppData%\npm

or

%USERPROFILE%\AppData\Roaming\npm

it worked for me on windows

YMG
  • 498
  • 6
  • 15
0

Permanently solution here for MACOS Users:

open terminal:

sudo vim /etc/Paths

add new line. (INSERT , press fn+i)

/Users/[your-user]/.npm-global/bin

press ESC , and then :wq (exit from editor)

restart terminal (close and open terminal again..) check the path;

~ % echo $PATH

it should be listed in path list now.. like below;

/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/[myuser]/.npm-global/bin ....

good job, ng command now,

ng version

Angular CLI: 14.1.0
Mucahid Uslu
  • 367
  • 3
  • 11
0

After trying everything here, what solved my issue was:

  1. Making sure I have the latest node.js version (re-install from here: https://nodejs.org/en/download/)
  2. Running the commands from the powershell
Yuval Peretz
  • 103
  • 1
  • 5
0

for me, on Linux:

you can open the .bashrc file from Home then, you will notice the following command right there:

# Load Angular CLI autocompletion.
source <(ng completion script)

comment out the "source" command that you see above by # sign then, save the file.

# source <(ng completion script)

reopen the terminal then, you could use it now.

you can now use the following command instead of ng:

open the working directory where the Angular project is there then, try this command instead:

$ npm start

you can open the package.json file and move to the line where the "scripts" key is, move to "start" key then, you will notice the ng serve that you were like to type then, you can add host and port from your choice like so:

"start": "ng serve --host 0.0.0.0 --port 4200"

Abdelhamed Abdin
  • 556
  • 1
  • 6
  • 19
0

You can probably come across this issue in many other ways, but this is what my scenario was, and if you have the same scenario this answer will help, or give you some knowledge.

The Scenario:

  1. You did NOT install nodejs through package manager, but rather you downloaded the binaries and saved at some path. I saved mine at /opt/node-v18.15.0.
  2. You did NOT add to the PATH variable the path to node, npm etc. rather you symlinked node, npm and npx to some well-known location. I created the symlinks at /usr/bin.

Now, if you install @angular/cli using npm install -g @angular/cli and then try to use ng, you will get the error:

ng: command not found

Note that installing @angular/cli creates the ng file (which is essentially a symlink to ../lib/node_modules/@angular/cli/bin/ng.js) at the same location as the node, npm and npx files are located, which for me was /opt/node-v18.15.0/bin. The reason you get this error is that this path is not in your PATH variable as you never added it!

Solution:

Add the node path to the PATH variable:

PATH=$PATH:/path/to/node/bin

That way you won't need to create the symlinks to node, npm etc. AND if any other npm package installation creates some other commands like ng in the bin folder, you will not face issues like this again.

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90