I am being more cautious than usual because I have been confused by the behavior of
npm in the past.
I am on a Mac and have installed node.js through
brew install node.
Now that I want to run
jslint.js on the command-line as the command
jslint 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 https://registry.npmjs.org/jslint npm http 200 https://registry.npmjs.org/jslint npm http GET https://registry.npmjs.org/jslint/-/jslint-0.1.9.tgz npm http 200 https://registry.npmjs.org/jslint/-/jslint-0.1.9.tgz npm http GET https://registry.npmjs.org/nopt npm http 200 https://registry.npmjs.org/nopt npm http GET https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz npm http 200 https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz npm http GET https://registry.npmjs.org/abbrev npm http 200 https://registry.npmjs.org/abbrev npm http GET https://registry.npmjs.org/abbrev/-/abbrev-l.0.4.tgz npm http 200 https://registry.npmjs.org/abbrev/-/abbrev-1.0.4.tgz /usr/local/share/npm/bin/jslint -> /usr/local/share/npm/lib/node_modules/jslint/ bin/jslint.js firstname.lastname@example.org /usr/local/share/npm/lib/node_modules/jslint └── email@example.com (firstname.lastname@example.org)
$ jslint ply.js zsh: command not found: jslint
/usr/local/share/npm/bin not being in my
1) Why did
brew not install global
bin path to path? Maybe it did, but something
zsh does is messing it up. Where might I be able to find that?
2) Should I do this? (Append
:/usr/local/share/npm/bin to the exported
$PATH 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
/usr/local/bin for any programs that I have trouble with and it should be good enough for my purposes.
EDIT: I'm updating this in 2019, because this old question is popular but now outdated both in terms of my personal workflow and also in terms of how to best go about installing node and managing its various dependencies.
My personal workflow is now to use the installer obtained from nodejs.org to install node on systems. I actually trust this more than the homebrew package itself, because it knows best how to manage the files. If you want to change your system node from 8.10 to 10.15, whether on Mac or Windows, simply download the installer from nodejs.org for 10.15 for your OS. Attempting to upgrade node installed via homebrew has always proven to be a more difficult approach in my experience.
Also, the biggest thing to point out is that the use of sudo as shown in my npm install of jslint example above is highly discouraged; I am fairly certain that homebrew packages should never be installed or interacted with in any way using the superuser. It should not be necessary, and will lead to file permission headaches!
Furthermore I recommend ESLint over jslint, and have not used jslint in years.
isn't a terrible idea. Having said that, you shouldn't have to do it.
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).
npm config set prefix /usr/localif it's something else, and
sudowith npm! According to the jslint docs, you should just be able to
If you installed npm as sudo (
sudo brew install), try reinstalling it with plain ol'
brew install. Homebrew is supposed to help keep you
Spent a while on this issue, and the PATH switch wasn't helping. My problem was the Homebrew/node/npm bug found here - https://github.com/npm/npm/issues/3794
If you've already installed node using Homebrew, try ****Note per comments that this might not be safe. It worked for me but could have unintended consequences. It also appears that latest version of Homebrew properly installs npm. So likely I would try
brew upgrade node etc before trying****:
npm update -gf
Or, if you want to install node with Homebrew and have npm work, use:
brew install node --without-npm curl -L https://npmjs.org/install.sh | sh