Vincent Chee
Vincent Chee

Reputation: 45

Why doesn't zsh recognize command from globally installed npm package?

After installing oh-my-zsh and reinstalling node and npm again, I install npm-check-updates globally and try to call 'ncu' (the npm-check-updates command). However, I get an error: zsh: command not found: ncu. Does anyone know how to fix this?

Upvotes: 3

Views: 4836

Answers (4)

Hermit-Z
Hermit-Z

Reputation: 61

I have corrected this problem with the following instructions:

sudo npm install -g npm-check-updates

Upvotes: 6

Vincent Chee
Vincent Chee

Reputation: 45

FYI I am using a OSX.

The problem was that my export path in my .zshrc was wrong. This was what it was previously:

export PATH=$HOME/bin:/usr/local/bin:$PATH.

Notice there is nothing pointing at npm or any of the packages I installed globally. For anyone who has this problem in the future...

  1. Ensure that npm is installed and that you can still run npm commands (if not uninstall then install npm). Then run npm -g list --depth 0 to list all your global packages.
  2. Go into your home folder and press +Shift+. (shows all hidden files/folders), there should be a .npm folder there, ensure the packages in the list you obtained in the previous step matches what's in the bin folder.
  3. Edit your export PATH string accordingly:

export PATH=$HOME/bin:/usr/local/bin:**$HOME/.npm/bin**:$PATH.

This worked for me!

Upvotes: 0

lolesque
lolesque

Reputation: 12020

After an install you can run rehash so zsh will analyse what new executables are available on $PATH.

Not sure if that would fix the problem, I know it fixes the missing tab completion entry after install.

Upvotes: 1

jasper
jasper

Reputation: 133

Make sure the 'ncu' package can be found in the $PATH environment variable. Try this, to find where 'ncu' is supposed to be installed:

which ncu

If it still gives you trouble, try to see if it's in /usr/bin, $HOME/npm/bin, /usr/local/lib or /usr/sbin, and check that your $PATH environment variable contains a way to 'ncu'. Your $PATH environment variable, which can be found in

$HOME/.bashrc (Linux)
$HOME/.bash_profile (MacOS)

should look something like this:

export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/npm/bin

Upvotes: 0

Related Questions