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
jslint@0.1.9 /usr/local/share/npm/lib/node_modules/jslint
└── nopt@1.0.10 (abbrev@1.0.4)
Subsequently
$ jslint ply.js
zsh: command not found: jslint
due to /usr/local/share/npm/bin
not being in my $PATH
.
1) Why did brew
not install global npm
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 ~/.zshrc
)
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 /usr/local/bin
maybe).
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.
brew should not require you to use sudo even when running npm with -g. This might actually create more problems down the road.
Typically, brew or port let you update you path so it doesn't risk messing up your .zshrc, .bashrc, .cshrc, or whatever flavor of shell you use.
If you have linked the node packages using sudo command
Then go to the folder where node_modules are installed globally.
On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. If you set the NODE_PATH environment variable to this path, the modules can be found by node.
Windows XP - %USERPROFILE%\Application Data\npm\node_modules Windows 7 - %AppData%\npm\node_modules
and then run the command
This will give the list of all global node_modules and you can easily see the linked node modules.
Any one got the same issue it's related to a conflict between brew and npm Please check this solution https://gist.github.com/DanHerbert/9520689
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 update
,brew doctor
,brew upgrade node
etc before trying****:Or, if you want to install node with Homebrew and have npm work, use:
sudo brew is no longer an option so if you install with brew at this point you're going to get 2 really obnoxious things: A: it likes to install into
/usr/local/opts
or according to this, /usr/local/shared. This isn't a big deal at first but i've had issues with node PATH especially when I installed lint. B: you're kind of stuck with sudo commands until you either uninstall and install it this way or you can get the stack from BitnamiI recommend this method over the stack option because it's ready to go if you have multiple projects. If you go with the premade MEAN stack you'll have to set up virtual hosts in httpd.conf (more of a pain in this stack than XAMPP)plust the usual update your extra/vhosts.conf and /etc/hosts for every additional project, unless you want to repoint and restart your server when you get done updatading things.
I use brew and the prefix was already set to be:
I did notice that the bin and lib folder were owned by root, which prevented the usual non sudo install, so I re-owned them to the user
Then I just added the path to my .bash_profile which is located at /Users/[user]