So I'm looking into learning node.js. I've been following this tutorial to install it and try some stuff out.
At any rate, npm is behaving really strangely. It'll work just fine for a while (I changed its viewer config settings, for instance), but then suddenly 'disappear', so that the next time I enter
npm ...(anything)
in the command line, my shell informs me that the npm command has not been found. Previously, uninstalling and then reinstalling npm using nvm has worked, but I'd rather not do this every ten minutes, and it's super weird to me that it will suddenly stop working.
I think the last time, it stopped working after I edited and then re-sourced my ~/.zshrc file -- just added npm and node tab-completion plugins.
Any idea what's going on? I'll post the results of a couple basic commands, but I'm really bad with sysadmin stuff, and I don't really know what to look for here.
nvm -ls
v0.8.22
current: v0.10.2
default -> 0.8 (-> v0.8.22)
which node
/usr/bin/node
which npm
npm not found
There's are both nvm (is this a duplicate?) and npm directories directly in my root folder.
If I go into /usr/bin, node is a file, not a directory. There's also a file npm, but not file nvm.
As all the above probably shows, I really have no idea what's going on. I've searched for this, but nobody seems to have this problem. Any ideas what's going on or how to find out?
EDIT Noticing that my default node isn't up-to-date, I did all this. Putting aside why my shell switched me automatically to the bin directory (and why that seems to be a github repo -- no idea what's up with my computer), does this provide any clues?:
➜ node nvm alias default v0.10.2
default -> v0.10.2
➜ node nvm ls
v0.8.22
current: v0.10.2
default -> v0.10.2
➜ node npm
zsh: command not found: npm
➜ node nvm install npm
######################################################################## 100.0%
Checksums do not match.
Binary download failed, trying source.
Additional options while compiling:
nvm: install N/A failed!
➜ bin git:(master) nvm uninstall npm
N/A version is not installed yet... installing
######################################################################## 100.0%
Checksums do not match.
Binary download failed, trying source.
Additional options while compiling:
nvm: install N/A failed!
➜ bin git:(master) cd ~/rails/node
EDIT 2 - I made sure the node path was added to my zshrc file:
#other stuff...
export PATH=(...):/usr/bin/node
But when I then tried to run
source ~./zshrc
I got this complaint:
.zshrc:11: command not found: npm
which points to these lines (numbers added):
10 . ~/nvm/nvm.sh
11 . <(npm completion)
which I got from following the above tut and, back when npm was working, looking up how to implement tab completion.
In response to Jens
This is in my ~/nvm/nvm.sh file, near the start:
# Auto detect the NVM_DIR
if [ ! -d "$NVM_DIR" ]; then
export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd)
fi
# Make zsh glob matching behave same as bash
# This fixes the "zsh: no matches found" errors
if [ ! -z "$(which unsetopt 2>/dev/null)" ]; then
unsetopt nomatch 2>/dev/null
fi
I tried to (and I think successfully did) chmod the npm directory to make it read/write/executable.
PATH
point to wherenode
is installed? – Restaurant/full/path/to/npm completion
. – Recollection