I am having a problem installing global node modules and everything I find online says the solve is just adding -g. Which is not the problem. I believe it's a linking issue or wrong directory issue.
Here is what I do:
$ npm install -g express
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/mkdirp/0.3.3
...downloads correctly
$ express myapp
bash: express: command not found
However when I run the direct link location to express it works:
$ /usr/local/share/npm/bin/express myapp
create : myapp
create : myapp/package.json
create : myapp/app.js
... Builds app correctly
Where the module is:
$ which node
/usr/local/bin/node
$ node -pe process.execPath
/usr/local/Cellar/node/0.8.20/bin/node
$ npm link express
/Users/bentonrr/Development/Personal/node_modules/express -> /usr/local/share/npm/lib/node_modules/express
In my .bash_profile I have:
export PATH=/usr/local/bin:$PATH
export NODE_PATH=/usr/local/lib/node_modules:/usr/local/lib/node
Do I need to change my Node environment to download to correct folder? Is something not linking correctly? I am lost..
Thanks!
Other Specs:
$ node --version
v0.8.20
$ npm --version
1.2.11
$ brew --version
0.9.4
OSX Version 10.8.2
Add /usr/local/share/npm/bin
to your PATH
(e.g., in .bashrc
).
For more info, see npm help npm
:
global mode:
npm installs packages into the install prefix at prefix/lib/node_modules and bins are installed in prefix/bin.
You can find the install prefix with npm get prefix
or npm config list | grep prefix
.
This may mean your node install prefix isn't what you expect.
You can set it like so:
npm config set prefix /usr/local
then try running npm install -g
again, and it should work out. Worked for me on a mac, and the solution comes from this site:
http://webbb.be/blog/command-not-found-node-npm/
EDIT: Note that I just came across this again on a new Mac I'm setting up, and had to do the process detailed here on stackoverflow as well.
I do not ever install any npm stuff, via sudo! I have my own reasons, but I just try to keep things simple, and user based, since this is a user development world, and not everyone has root access, and root/sudo installing things like this just seems to clutter up things to begin with. After all, all developers should be able to follow these instructions, not just privileged sudo users.
This particular system is a RHEL7 accessed via SSH:
Frequently one needs various versions of node, so I use NVM https://github.com/creationix/nvm
So with that said, I can show you a working example for -g
global installs, using NVM, NPM, and node paths not using root.
set your prefix for .npm-packages
if it isn't already. (note, thats a hyphen, not an underscore)
nvm config ls
prefix = "/home/<yourusername>/.npm-packages"
Then adjust your ~/.bash_profile or .bashrc if you prefer readup on why and which here, with the following information.
#PATH EXPORTS
NODE_MODULES=$HOME/.npm
NPM_PACKAGES=$HOME/.npm-packages/bin
export PATH=$PATH:$HOME/bin:$NODE_MODULES:$NPM_PACKAGES
#NVM ENABLE
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
That pretty much covers all paths. For e.g., if you install gulp like this npm install -g gulp
it symlinks in ~/.npm-packages/bin
(note thats a hyphen, not an underscore). (no need for gulp-cli
, or gulp-cl
)
You can pretty much replace/comment-out all other node path exports. You can put this path info below any other path info you already have, safely, without it overwriting that stuff.
The problem I had was missing the binaries because the user specific .npmrc file in my home directory had bin-links
set to false
, though the default is true
.
Just in case this is your problem check that none of your .npmrc files have it set to false.
Then re-installing all modules will create the binaries at the prefix
so your PATH
can see them.
Steps
First, remove Node:
sudo rm -rf /usr/local/lib/node_modules/jitsu
npm cache clear
sudo npm install jitsu -g
Second, create .bash_rc:
vi ~/.bash_rc
Copy following items and paste into the file, opened in step 2:
[[ -s ~/.bashrc ]] && source ~/.bashrc
export PATH=/usr/local/share/npm/bin:$PATH
Run Jitsu. Run vi ~/.bash_profile, this is what you should see:
[[ -s ~/.bashrc ]] && source ~/.bashrc
export PATH=/usr/local/share/npm/bin:$PATH
# {{{
# Node Completion - Auto-generated, do not touch.
shopt -s progcomp
for f in $(command ls ~/.node-completion); do
f="$HOME/.node-completion/$f"
test -f "$f" && . "$f"
done
# }}}
I found the answer for removing Node from this article:
JITSU FAILED TO INSTALL OSX [node 0.8.17 and NPM 1.2.0] WTF