angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

-bash: ng: command not found

Open YuvPrime opened this issue 9 years ago • 33 comments

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.

YuvPrime avatar Feb 26 '17 14:02 YuvPrime

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

Brocco avatar Feb 26 '17 16:02 Brocco

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.

YuvPrime avatar Feb 27 '17 07:02 YuvPrime

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

stokwell avatar Feb 28 '17 19:02 stokwell

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

Brocco avatar Mar 01 '17 04:03 Brocco

It worked for me:

npm link @angular/cli

wilfil avatar Jun 08 '17 16:06 wilfil

how to resolve path pls help

nikhilshejwal avatar Jun 22 '17 20:06 nikhilshejwal

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

ravi651 avatar Jul 22 '17 08:07 ravi651

Do this & check again

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

neilhem avatar Jul 22 '17 08:07 neilhem

its not working screenshot 22

ravi651 avatar Jul 22 '17 08:07 ravi651

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

naru6be avatar Jul 22 '17 13:07 naru6be

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?

omaracrystal avatar Aug 17 '17 04:08 omaracrystal

How to set the path: https://ovinitech.blogspot.com/2017/08/ng-is-not-recognized-as-internal-or.html

Ovini avatar Sep 01 '17 06:09 Ovini

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)

kbradl16 avatar Sep 30 '17 18:09 kbradl16

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

meghma avatar Oct 17 '17 13:10 meghma

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.

lytecode avatar Oct 30 '17 13:10 lytecode

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.

itskawsar avatar Nov 12 '17 20:11 itskawsar

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

riyajk avatar Nov 20 '17 07:11 riyajk

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

egarson avatar Dec 28 '17 00:12 egarson

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

shanemac10 avatar Mar 28 '18 20:03 shanemac10

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

clydin avatar Mar 28 '18 21:03 clydin