Steven Lu Steven Lu - 1 month ago 16
Node.js Question

npm global path prefix

I am being more cautious than usual because I have been confused by the behavior of

in the past.

I am on a Mac and have installed node.js through
brew install node

Now that I want to run
on the command-line as the command
I find that the canonical way to accomplish this is
sudo npm install -g jslint
which ran successfully with this output:

$ sudo npm install -g jslint
npm http GET
npm http 200
npm http GET
npm http 200
npm http GET
npm http 200
npm http GET
npm http 200
npm http GET
npm http 200
npm http GET
npm http 200
/usr/local/share/npm/bin/jslint -> /usr/local/share/npm/lib/node_modules/jslint/
jslint@0.1.9 /usr/local/share/npm/lib/node_modules/jslint
└── nopt@1.0.10 (abbrev@1.0.4)


$ jslint ply.js
zsh: command not found: jslint

due to
not being in my

1) Why did
not install global
path to path? Maybe it did, but something
does is messing it up. Where might I be able to find that?

2) Should I do this? (Append
to the exported
at the bottom of my

It seems like this isn't the right way to do it because if I install something else later (using Homebrew or something) I'll be needing to append it to my zsh startup script to set the path. I guess in this particular instance it's just a matter of the
npm install -g
not making the right symlinks in a "proper" location (like

I think what I will do is manually build out symlinks inside
for any programs that I have trouble with and it should be good enough for my purposes.


Extending your PATH with:

export PATH=/usr/local/share/npm/bin:$PATH

isn't a terrible idea. Having said that, you shouldn't have to do it.

Run this:

npm config get prefix

The default on OS X is /usr/local, which means that npm will symlink binaries into /usr/local/bin, which should already be on your PATH (especially if you're using Homebrew).


  1. npm config set prefix /usr/local if it's something else, and
  2. Don't use sudo with npm! According to the jslint docs, you should just be able to npm install it.

If you installed npm as sudo (sudo brew install), try reinstalling it with plain ol' brew install. Homebrew is supposed to help keep you sudo-free.