为什么brew说安装了nodejs?

Why does brew say that nodejs is installed?

首先,我在 macOS 终端中 运行 node,然后得到

bash: /usr/local/bin/node: No such file or directory    

我运行brew install node得到

Warning: node 12.10.0 is already installed, it's just not linked You can use `brew link node` to link this version.

所以我 运行 brew link node 得到

Error: Could not symlink include/node/common.gypi                                                                 
/usr/local/include/node is not writable.   

我想这是一些权限问题。所以我 运行 它与 sudo 和 get

Error: Running Homebrew as root is extremely dangerous and no longer supported.                                   
As Homebrew does not drop privileges on installation you would be giving all                                      
build scripts full access to your system. 

然后我尝试brew uninstall node,并重复上述所有步骤,仍然得到相同的错误。我该怎么办?

注意:切勿将 sudobrew 一起使用。 运行 brew 因为 root 可能会更改 brew 相关文件的所有者,并使其无法被当前用户访问。

问题的答案:您可能已经通过使用sudo破坏了/usr/local/include/node目录的权限。要解决此问题,

rm -rf /usr/local/include/node
brew unlink node
brew link node

如果上述命令不能解决您的问题。尝试递归修复 /usr/local 下的所有文件夹权限。然后再次尝试上述修复。

sudo chown -R $(whoami):admin /usr/local/*

我明白了。做 brew link --overwrite node 工作。