所以我正在学习node.js。我一直在按照这篇教程进行安装并尝试使用一些东西。
无论如何,npm的行为非常奇怪。它会工作一段时间(例如,我更改了它的查看器配置设置),但突然间“消失”,以至于下次我输入时...
npm ...(anything)
在命令行中,我的shell告诉我找不到npm命令。以前,使用nvm卸载然后重新安装npm是有效的,但我不想每十分钟这样做,而且对我来说很奇怪,它突然就停止工作了。我认为最后一次,它在我编辑并重新加载~/.zshrc文件后停止工作 - 只是添加npm和node tab-completion插件。
有什么想法吗?我将发布一些基本命令的结果,但我真的不擅长sysadmin方面的东西,也不知道在这里应该寻找什么。
nvm -ls
v0.8.22
current: v0.10.2
default -> 0.8 (-> v0.8.22)
哪个节点
/usr/bin/node
哪个是npm
npm not found
在我的根目录中,有直接包含 nvm(这是重复的吗?)和 npm 目录。
如果我进入 /usr/bin,node 是一个文件,不是一个目录。还有一个文件叫做 npm,但没有 nvm 文件。
正如以上所有内容所显示的那样,我真的不知道发生了什么。我已经搜索过了,但似乎没有人遇到这个问题。有什么想法或者如何找出原因吗?
编辑 注意到我的默认 node 不是最新的版本,我进行了所有这些操作。抛开为什么我的 shell 自动切换到 bin 目录(以及为什么那似乎是一个 GitHub 存储库 - 不知道我的电脑怎么回事),这提供了任何线索吗?
➜ 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
编辑2 - 我确保将节点路径添加到了我的zshrc文件中:
#other stuff...
export PATH=(...):/usr/bin/node
但是当我尝试运行时
source ~./zshrc
我收到了这个投诉:
.zshrc:11: command not found: npm
指向以下行的位置(已添加行号):
10 . ~/nvm/nvm.sh
11 . <(npm completion)
这是我从上面的教程中学到的,并且在npm还能正常工作的时候,查找如何实现选项卡自动补全。
回应Jens:
这段代码出现在我的~/nvm/nvm.sh文件中,靠近开头部分:
# 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
我尝试并且认为已经成功地将npm目录的chmod设置为读写可执行。
PATH
是否指向node
安装的位置? - alex/full/path/to/npm completion
。 - Jens