6

I'm trying to setup Angular 2 using "npm install @angular/cli -g "

After the install, the only warning I see is the UNMET PEER DEPENDENCY rxjs@^5.0.1, which I then install and reinstall "npm install @angular/cli -g"

No matter what I do, or what version of Node I setup with n, I keep getting the following message when trying to user the "ng" commands:

zsh: command not found: ng

I've been looking around and have not found a solution for this.

Has anyone run into this and have any suggestions?

UPDATE:

It looks like this is not a angular/cli specific issue.

I now see that I get the same message when I try to run "Grunt" and "Ionic" commands on an existing project that was working fine.

zsh: command not found: ionic zsh: command not found: grunt

2
  • Drop the @ and try it again. If that doesn't work, you may have run sudo npm install at some point, if that's the case you'd need to run sudo npm install -g angular/cli due to permission issues. You can typically fix that using chown or chmod on your ~/.npm folder. If that doesn't work, uninstall angular/cli and reinstall it. Commented Feb 19, 2017 at 3:58
  • Hi Austin, I tried your suggestions, but it didn't work. I now have noticed that on an existing project, where I use grunt, it get's a similar message when trying to run the grunt command: zsh: command not found: grunt. I'm thinking there is more to this than just angular/cli.
    – cnak2
    Commented Feb 19, 2017 at 18:14

1 Answer 1

13

Most likely, the directory in which the global modules are installed is not in your $PATH -- and therefore unknown to your shell.

To fix this issue, we can create a new directory for global node_modules, configure npm to use it, and add that directory to your $PATH.

# create a new directory where npm will install packages
$  mkdir ~/.node_modules

# set npm "prefix" config to that directory
$  npm config set prefix '~/.node_modules'

# append a line to your .zshrc instructing it to include that directory in your $PATH, making the executables known to the shell
$ echo 'export PATH=~/.node_modules/bin:$PATH' >> ~/.zshrc

# update current shell with new path (not needed for new sessions)
$ source ~/.zshrc

Then, first reinstall the latest npm (npm i -g npm), followed by the global packages you need (npm i -g @angular/cli).

For more on PATH, see this definition: http://www.linfo.org/path_env_var.html

2
  • I tried this solution, but got an error with my nvm. Any advice on the work around? Your user’s .npmrc file (${HOME}/.npmrc) has a globalconfig` and/or a prefix setting, which are incompatible with nvm. Run nvm use --delete-prefix v20.11.1 --silent to unset it.`
    – dko
    Commented Mar 26 at 22:48
  • ^ what worked for me was running npm cache verify before nvm install -g @angular/cli didn't need to add thte prefix or edit the .zshrc file (solution here)
    – dko
    Commented Mar 28 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.