Mac 卸载 node npm

先使用 brew 卸载 node

➜  ~ brew -v
Homebrew 2.0.3
Homebrew/homebrew-core (git revision b295f; last commit 2019-03-09)

执行 brew uninstall node

如果出现拒绝卸载,例如如下情况

➜  ~ brew uninstall node 
Error: Refusing to uninstall /usr/local/Cellar/node/11.1.0
because it is required by yarn, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies node

忽略依赖卸载 node brew uninstall --ignore-dependencies node

➜  ~ brew uninstall --ignore-dependencies node
Uninstalling /usr/local/Cellar/node/11.1.0... (3,936 files, 47.0MB)
node 10.8.0 is still installed.
Remove all versions with `brew uninstall --force node`.
➜  ~ node -v
v13.6.0

执行 brew uninstall --force node 卸载所有版本

➜  ~ brew uninstall --force node
Uninstalling node... (4,022 files, 48.7MB)
➜  ~ node -v
v13.6.0
➜  ~ brew uninstall node
Error: No such keg: /usr/local/Cellar/node
➜  ~ node -v
v13.6.0

手动清理 node 相关目录和文件

1.进入 /usr/local/lib 目录删除 node, node_modules 相关文件夹

sudo rm -rf node_modules 这里需要使用管理员权限

➜  lib pwd    
/usr/local/lib
➜  lib sudo rm -rf node_modules

2.进入 /usr/local/include 目录删除 node, node_modules 相关文件夹

rm -rf node/

➜  include pwd
/usr/local/include
➜  include rm -rf node/     

3.检查 ~/local 目录下的 node, node_modules 相关文件夹, user 为本机用户名

➜  ~ find ~/local -name node
/Users/user/local/bin/node
/Users/user/local/include/node
/Users/user/local/share/doc/node
➜  ~ find ~/local -name node_modules
/Users/user/local/lib/node_modules

rm -rf /Users/user/local/bin/node /Users/user/local/include/node /Users/user/local/share/doc/node /Users/user/local/lib/node_modules

➜  ~ rm -rf /Users/user/local/bin/node /Users/user/local/include/node /Users/user/local/share/doc/node /Users/user/local/lib/node_modules`

4.检查 ~/lib 目录下的 node, node_modules 相关文件夹

➜  ~ find ~/lib -name node
➜  ~ 
➜  ~ find ~/lib -name node_modules
/Users/user/lib/node_modules
/Users/user/lib/node_modules/npm/node_modules
...

rm -rf /Users/user/lib/node_modules

5.检查 ~/include 目录下的 node , node_modules 相关文件夹

➜  ~ find ~/include -name node 
/Users/user/include/node
➜  ~ find ~/include -name node_modules
➜  ~ 

rm -rf /Users/user/include/node

~ 目录下执行如下命令删除文件

➜  ~ pwd
/Users/user
➜  ~                                

rm -rf node-*

rm -rf .npm .npminstall_tarball

删除完毕后,重启一下终端,输入 node -v 检查 node 是否还存在。

Last login: Mon Jan 20 11:39:02 on ttys000
➜  ~ node -v
zsh: command not found: node

相关链接:
Ubuntu卸载Node

你可能感兴趣的:(Mac 卸载 node npm)