通过 PKG 安装 Node 后找不到 NPM 命令(无 brew)

NPM command not found after installing Node via PKG (no brew)

我尝试删除 NPM 和 Node,然后重新安装它们。正如您所注意到的,我在这个过程中完全是个菜鸟。

遗憾的是我不记得我使用的命令。

删除它们后,我 运行 node -v 返回 command not found 并且我 运行 npm -v 返回 command not found,所以我认为这个过程是成功的。

然后我去了 Nodejs 网站并下载了适用于 MacOS 的最新软件包 (v12.11.1) 和 运行 安装。据说成功了。我检查了 node -v,它按预期返回了 12.11.1,但后来我检查了 npm -v,它遗憾地返回了 npm not a command!!

如果我 运行 which node 我得到 /usr/local/bin/node。如果我 运行 which npm 我什么也得不到。

从那以后,我尝试了很多方法来再次删除它们,以防万一遗漏了什么,但我每次都得到同样的东西——没有 NPM!

Whosebug 上的大多数答案都在谈论 Brew,但我没有使用过 Brew,而且我尝试了很多其他答案,但就是无法恢复 NPM。

PKG 安装程序提到了这一点:'Make sure that /usr/local/bin is in your $PATH.' 但不完全确定那是什么意思,是否是我的问题。

有没有人知道一个可靠的方法来删除两者的所有痕迹,所以当我从 Node 重新安装 PKG 时,我安装了 Node 和 NPM 并正常工作?

更新:

自发布这个问题以来,我似乎取得了一些成功。我按照 https://docs.npmjs.com/misc/removing-npm.html 中的说明再次手动删除 'everything NPM-rleated' 和 运行 安装程序。现在当我检查 npm -v 它 returns 到最新版本号 6.11.3.

我会在 deleting/answering 我自己的问题之前再测试一下。

谷歌搜索 'Adding to $PATH mac' returns 这是最高结果:

https://www.architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/

Open up Terminal and run the following command:

sudo nano /etc/paths

Enter your password, when prompted.

Go to the bottom of the file, and enter the path you wish to add.

Hit control-x to quit.

Enter “Y” to save the modified buffer.

That’s it! To test it, in new terminal window, type:

echo $PATH

为了解决这个问题,我 运行 按照 NPM 的建议执行了以下命令:

To remove everything npm-related manually:

rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*

在我重新安装 Node 并使用 npm -v 检查 NPM 版本后一切正常。

这就是我在 mac

上所做的
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
brew uninstall node
brew install node