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…
This will basically get you down to base of your files.
To “list all” your files use…
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.
Then “list-all” to see if “ng” shows up…
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..
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…
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…
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…
You should see your new path on the end. Here’s mine…
Neato! Now try “ng” out…
There you go. It’s permanent.
More info about Mac OS Paths…