Ways to fix “-bash: ng: command not found”
Tags: angular, angularcli
Published: 2019-11-17 14:45:52

---
title: Ways to fix “-bash: ng: command not found”
published: true
date: 2019-11-02 21:20:27 UTC
tags: angular,angular-cli
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/590/1*1bh2mszm6rtMXA8F-IbPjw.jpeg)

#### What you have already tried

```
ng version
```

or any other _ng_ commands.

#### Error produced by the previous command

```
-bash: ng: command not found
```

#### Before heading into the fix, let me ask a question

Are you sure that Angular is globally installed in your machine? If yes, you can continue to read this article. Else I recommend you to visit the [official Angular site](https://angular.io/guide/setup-local) and get the latest version installed :)

This problem is caused due to the reason that **npm is unable to find ng.** There are few ways that we can follow to get rid of this error.

#### 1 . Linking angular/cli with npm

This can be done using the command,

```
npm link @angular/cli
```

#### 2. Setting the location of npm folder

```
export PATH="$HOME/.npm-global/bin:$PATH"
```

or

```
export PATH="$HOME/.npm-packages/bin:$PATH"
```

#### 3. Clearing cache and Re-installing Angular (least recommended)

In this case, you may need to uninstall angular from your machine with the command

```
npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli
```

#### 4. Giving an alias to ng path

To do this you must know the full path of your angular installation. For example: _“/Users/\<username\>/.npm-global/lib/node\_modules/@angular/cli/bin/ng”._ So the command would be

```
alias ng="/Users/Dharshini/.npm-global/lib/node\_modules/@angular/cli/bin/ng"
```

Note that the above option works for many users but the problem is that this is just a temporary solution. It means that this command works only on your current terminal (same terminal where you ran the above command). Once you close and open a new terminal, the problem seems to reappear.

So how can we permanently solve this? Here comes the solution. _Credits:_ [_Thanks for this fix_](https://github.com/angular/angular-cli/issues/5021#issuecomment-377030706)_._

#### 5 . By adding the PATH directly to the Mac OS terminal

Before doing this we just have to verify whether angular is installed to the base of the user. To check this, in your terminal enter

```
cd ~
```

to get to the base of your files. Then in order to list all your base files, enter

```
ls -a
```

Now you must see “_.npm-global_” listed in the files.

![](https://cdn-images-1.medium.com/max/426/1*kB_uuT6Jn_siQhbTDcScMw.jpeg)

If its not there, again I recommend you to install Angular using the official documentation link I have mentioned in the beginning.

If the folder is listed, you are good to go. Go back to the base of the user using the command

```
cd ~
```

Here we are going to edit the paths using vim editor. Use “_sudo_” in front of the command to avoid permission issues. Here you will be prompted to enter the device’s password.

```
sudo vim /etc/paths
```

The editor now opens a file containing some paths as shown below. All you have to do here is to insert the path of _.npm-global/bin_ to the list. To do so you have to press insert from your mac keyboard (press _fn + i_ key combination), navigate to the bottom of the list and add ~/.npm-global/bin as I have added below.

```
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
~/.npm-global/bin
~ 
~
```

Now to save your changes and exit, press _ESc_ key and then type :wq vim command which means to write/save the changes and quit. This will bring you back to the terminal window. Now restart your terminal and type

echo $PATH

This should give you all the paths with the newly added one concatenated at the end.

**_/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/.npm-global/bin_**

Finally the happy ending. Try any _ng_ command

```
ng version
```

There you go! Thanks for reading this article. Have a great day!