這里我在網(wǎng)上搜了兩個(gè)方法
一. 文章鏈接:http://www.cnblogs.com/snandy/p/4418615.html
- 拷貝如下代碼放到一個(gè)sh文件中(如uninstall_node.sh)
#!/bin/bash
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom \
| while read i; do
sudo rm /usr/local/${i}
done
sudo rm -rf /usr/local/lib/node \
/usr/local/lib/node_modules \
/var/db/receipts/org.nodejs.*
-
需要修改uninstall_node.sh文件屬性
有的會(huì)提示 “Permission denied”
輸入如下命令修改文件屬性
chmod 777 uninstall_node.sh
-
mac終端下執(zhí)行該文件柳琢,可以把uninstall_node.sh直接拖到終端绵跷,然后等上大概1分鐘
原文說這樣就卸載完成了喘落,但是在我的Mac里輸入node還是可以運(yùn)行的荒叼,而輸入npm則提示commang not found方妖,說明這段腳本只成功卸載了npm荤崇,而沒有卸載完成node,所以又找了第二段腳本代碼潮针。
二. 文章鏈接:http://www.tuicool.com/articles/Vzquy2
如果之前是在官網(wǎng)下載的 node 安裝包术荤,運(yùn)行后會(huì)自動(dòng)安裝在全局目錄,其中
node 命令在 /usr/local/bin/node 每篷,npm 命令在全局 node_modules 目錄中瓣戚,具體路徑為 /usr/local/lib/node_modules/npm
安裝 nvm 之后最好先刪除下已安裝的 node 和全局 node 模塊:
npm ls -g --depth=0 #查看已經(jīng)安裝在全局的模塊,以便刪除這些全局模塊后再按照不同的 node 版本重新進(jìn)行全局安裝
sudo rm -rf /usr/local/lib/node_modules #刪除全局 node_modules 目錄
sudo rm /usr/local/bin/node #刪除 node
cd /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs rm #刪除全局 node 模塊注冊(cè)的軟鏈
如圖所示焦读,輸入以上命令后子库,輸入node也提示command not found了,證明node也卸載成功矗晃。