Angular-cli: -bash: ng: command not found

Created on 26 Feb 2017  路  33Comments  路  Source: angular/angular-cli

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.

Most helpful comment

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)_

All 33 comments

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

Done everything as you said. When running npm install -g @angular/cli, it installs everything but
it shows error -bash: ng: command not found when running ng help.

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

Seems like a path issue, but it seems like you've found a workaround, closing.

It worked for me:

npm link @angular/cli

how to resolve path pls help

ng help
'ng' is not recognized as an internal or external command,
operable program or batch file.
os -windows
help me why this error is occurring

Do this & check again

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

its not working
screenshot 22

At last find the solution for ng command is not working issue ,Find the solution below http://itechiesol.blogspot.com/2017/07/angular-cli-ng-command-is-not-working.html

Could someone please explain how to solve the path issue. Also, I seem to run into Path issue frequently - is there any recommendations on a solution to prevent the Path issue reoccurring?

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)_

Finally, someone had the answer and steps to resolve the frustrating problem I (and many others too) was having! Thanks @kbradl16

Please take a look at this solution before running the commands by @kbradl16

@kbradl16; you a LifeSaver. God bless you for this solution.

Please guys, if you are facing this problem, kindly use the solution by @kbradl16; it worked like magic for me.

Am Using:
Ubuntu 14.04 64bit
node 8.6.0
npm 5.3.0

I hope it will work for you too.

In my Windows ng is working with Command Prompt. You can try it instead of Bash.

But it is showing the following issue when I run ng command:

As a forewarning, we are moving the CLI npm package to "@angular/cli" with the n
ext release,
which will only support Node 6.9 and greater. This package will be officially de
precated
shortly after.

To disable this warning use "ng set --global warnings.packageDeprecation=false".

I actually don't get why this is not working in Bash. I have double checked my PATH and everything is ok with the PATH.

Follow below steps.

From neilhem commnets

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

in your .bashrc file append below command.

alias ng="~/.npm-global/node_modules/@angular/cli/bin/ng"

restart terminal.

Notes :
Tested on
NODE version : 6.9.11
NPM version : > 5

If you have read this far, ensure you do not have an alias named ng
image

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

Alternatively, you can use nvm to install and manage Node.js.

I solved my problem by making a symbolic link, as long as I started an instance of the terminal or the problem.

sudo ln -s /Users/myuser/.npm-global/lib/node_modules/@angular/cli/bin/ng /usr/bin/ng

Please add sudo before the code of installing npm.

sudo npm install -g @angular/cli

try this

node 10.x
npm 6.x
Mac High Sierra

1) npm i -g @angular/cli
2) in .bash_profile -> alias ng='~/.npm-packages/bin/ng'

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.

Just install angular again
sudo npm i -g @angular/cli@(cli version you are using)
it is working for me

Much simpler: What helped me was to repeat the following cmd inside VSCode Terminal:
npm install -g @angular/cli

After doing so, the ng version cmd (and all the other nice angular cmds) worked well inside VSCode-Terminal.

These are the codes i used

sudo npm uninstall -g angular-cli
sudo npm uninstall -g @angular/cli
sudo npm cache clean --force
npm install -g @angular/cli
alias ng="~/node_modules/@angular/cli/bin/ng"

for check
ng --version

I had this issue and after going through it over and over again I discovered that some process had changed:

~/.npmrc

a flag had bin added that said:

binlink=false

deleting this flag completely solved all my npm issues

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

thank you so much

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

Thanks!

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

Thanks! Obrigado

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

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings