Solvedangular cli -bash: ng: command not found

Please provide us with the following information:

OS?

Mac OSX (Seirra)

Versions.

Node Version v7.6.0, NPM Version 4.1.2

The log given by the failure.

-bash: ng: command not found

Mention any other details that might be useful.

Installed angular cli by npm install -g @angular/cli and it doesn't shows any error. But running ng shows command not found error.


Thanks! We'll be in touch soon.

34 Answers

✔️Accepted Answer

This was a pain to figure out, so here is my solution

  1. npm install -g @angular/cli

  2. Make sure the ng path is correct

    • cd ~/npm-global/bin
    • ls and make sure ng exists
  3. create .bashrc file on your home directory

    • touch ~/.bashrc
    • vim ~/.bashrc
  4. Add ng as alias

    • press a (enables edit mode) then type in the following
    • alias ng="~/npm-global/bin/ng"
    • press esc (to get out of edit mode) then :wq (in vim will save)
  5. Temporarily Update .bashrc reference
    Your terminal wont take bash updates until a restart but the following command will let you use the updates during the terminal session:

    • source ~/.bashrc
  6. Check that ng works

    • ng --version

Hope that helps someone!

EDIT: To use this method you must be in a bash prompt or add the source ~/.bashrc to your terminal session. You can get into one by typing bash then enter in your terminal window. @shanemac10 's answer below will add it to your normal terminal by appending your mac PATH. (the one difference for me was my npm-global folder did not have a '.' in front of it)

Other Answers:

Permanent Fix - Dummy Version

Thank you kbradl16 for your solution. I am expanding and amending your answer to add "." to the file path (as it was required for me), and to make the PATH permanent in Mac OS, rather than having to re-load the source every time you open the terminal.

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

Please run the following and report back.

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

i try npm link @angular/cli, and its work, i don't now exactly why, something was wrong with command line

It worked for me:

npm link @angular/cli

More Issues: