前段时间我用 Homebrew 安装了 node 和 npm,它们都运行良好,直到今天我一直遇到 npm 命令未找到 错误。
什么时候运行 $ whereis node ,我什么也没得到
当我执行 $ which node 时,我看到 /usr/local/bin/node
当我执行 $ node -v 时,我看到 v4.4.7
当我做 $ whereis npm 时,我什么也得不到
当我执行 $ which npm 时,我什么也得不到
当我执行 $ npm -v 时,我看到 -bash: npm: command not found
我努力了
$ brew update
$ brew uninstall npm
$ brew install npm
我还确保设置了我的 $NODE_PATH
环境变量:
# In ~/.bash_profile file:
export NODE_PATH="/usr/local/lib/node_modules"
我还遵循了 https://himanen.info/solved-npm-command-not-found/ 的这些说明
似乎没有任何效果,当我使用 npm 在任何文件夹中运行任何命令时,我不断收到 npm: command not found 。有任何想法吗?谢谢
原文由 OneMoreQuestion 发布,翻译遵循 CC BY-SA 4.0 许可协议
想通了这个问题。所以问题的根源是我使用 Homebrew 安装了 npm,而 Homebrew 和 npm 的底层发生了一些问题。
为了解决这个问题,我做了以下事情:
重要的! 在 .bash_profile 中执行此操作
现在一切都像魅力一样