Angular

Ways to fix “-bash: ng: command not found”

Pinterest LinkedIn Tumblr

Permanent Fix – Dummy Version

1) Install Angular-CLI

This is your new master key to install angular-cli
sudo npm install -g @angular/cli --unsafe-perm=true --allow-root

Change it up as you see fit, but the options at the end seem to overwrite some install permission issues I’ve been experiencing lately. The allow-root may not be needed, but it doesn’t hurt anything.
See here for details…

2) Verify ng was added

From a terminal window and use the following command…
cd ~

This will basically get you down to base of your files.
To “list all” your files use…
ls -a

You should see “.npm-global” global listed. Note the “.” before the folder name.
You can “change directory” into the folder to see if your “ng” angular file was installed.
cd .npm-global/bin
or
cd .npm-global
cd bin

Then “list-all” to see if “ng” shows up…
ls -a

If it’s not there and you definitely installed angular-cli without any errors, then I don’t know what’s wrong. You have another problem.

Cool. Your ng file is there and now we are going to tell your terminal to look at this file every time you type a command that starts with “ng”

3) Add a PATH to Mac OS Terminal

Let’s go back to the base of your files again..
cd ~

Now we are going to open an existing file called “paths”, and we going to update it with your new path to the ng file we just added. You need to use SuperUserDo (sudo) to have write permissions. I’m going to use vim as my editor, but you can use nano, or whatever.
sudo vim /etc/paths

Cool. Now you are looking at a file that probably looks like this…

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

This is my file above. I added ” ~/.npm-global/bin” into the last spot. You have to press “i” to get vim into “–insert–” mode, go down to the end of the last line, and hit enter to get a new blank like, and paste in the file path exactly as I have. I tried it with and without the ” ~” and the ‘”/” both, just see what works, and for me it only worked as…
~/.npm-global/bin

Now that you pasted that in, press “ESC” and then type “:wq”, then enter. This tells vim to write(save) the file, and quit. If you get a permissions error, you didn’t use “sudo”, then you need to use “:q”, then enter to escape. Then try opening it again with “sudo”.

4) Refresh and Checking

Now you can take a look at your old paths by typing…
echo $PATH

Don’t see your spiffy new path? Well you need to re-start you terminal now. Now, you need to actually QUIT your terminal, like by using CMD+Q or by going to the top-bar options of Terminal > Quit Terminal. If you have any other terminals running in editors like VS Code or Atom, kill those too for good measure.

Now open terminal fresh again, and again type…
echo $PATH

You should see your new path on the end. Here’s mine…

/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/.npm-global/bin

Neato! Now try “ng” out…
ng help

There you go. It’s permanent.
More info about Mac OS Paths…

Source: https://github.com/angular/angular-cli/issues/5021#issuecomment-377030706

Write A Comment

Faster PHP Cloud Hosting