如何卸载从 pkg (Mac OS X) 安装的 nodejs?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9044788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I uninstall nodejs installed from pkg (Mac OS X)?
提问by Varvara Stepanova
I installed NodeJS from pkg file on my Mac. Now I need to uninstall it. Tell me please how to do it. I tried to remove files from this list:
我从 Mac 上的 pkg 文件安装了 NodeJS。现在我需要卸载它。请告诉我怎么做。我试图从此列表中删除文件:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom
But node is still on my computer.
但是节点仍然在我的电脑上。
回答by nicerobot
I ran:
我跑了:
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.*
Coded into gist 2697848
编码为要点 2697848
UpdateIt seems the receipts .bomfile name may have changed so you may need to replace org.nodejs.pkg.bomwith org.nodejs.node.pkg.bomin the above. The gist has been updated accordingly.
更新似乎收据.bom文件名可能已经改变,所以你可能需要更换org.nodejs.pkg.bom与org.nodejs.node.pkg.bom在上面。要点已相应更新。
回答by Afreekano
回答by Trefex
Following previous posts, here is the full list I used
在之前的帖子之后,这是我使用的完整列表
sudo npm uninstall npm -g
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
brew install node
回答by t0r0X
In order to delete the 'native' node.js installation, I have used the method suggested in previous answers sudo npm uninstall npm -g, with additional sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*.
为了删除“本机”node.js 安装,我使用了之前答案中建议的方法sudo npm uninstall npm -g,并添加了sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*.
BUT, I had to also delete the following two directories:
但是,我还必须删除以下两个目录:
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
Only after that I could install node.js with Homebrew.
只有在那之后我才能用 Homebrew 安装 node.js。
回答by AhrB
This is the full list of commands I used (Many thanks to the posters above):
这是我使用的命令的完整列表(非常感谢上面的海报):
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
brew install node
回答by alexbhandari
Use npm to uninstall. Just running sudo npm uninstall npm -gremoves all the files.
To get rid of the extraneous stuff like bash pathnames run this (from nicerobot's answer):
使用 npm 卸载。只需运行即可sudo npm uninstall npm -g删除所有文件。要摆脱诸如 bash 路径名之类的无关内容,请运行此命令(来自 nicerobot 的回答):
sudo rm -rf /usr/local/lib/node \
/usr/local/lib/node_modules \
/var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/lib/node \
/usr/local/lib/node_modules \
/var/db/receipts/org.nodejs.*
回答by hailong
I took AhrB's list, while appended three more files. Here is the full list I have used:
我拿了 AhrB 的清单,同时附加了三个文件。这是我使用过的完整列表:
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/systemtap/tapset/node.stp
sudo rm /usr/local/lib/dtrace/node.d
# In case you want to reinstall node with HomeBrew:
# brew install node
回答by Misha Tavkhelidze
A little convenience script expanding on previous answers.
一个扩展先前答案的便利脚本。
#!/bin/bash
# Uninstall node.js
#
# Options:
#
# -d Actually delete files, otherwise the script just _prints_ a command to delete.
# -p Installation prefix. Default /usr/local
# -f BOM file. Default /var/db/receipts/org.nodejs.pkg.bom
CMD="echo sudo rm -fr"
BOM_FILE="/var/db/receipts/org.nodejs.pkg.bom"
PREFIX="/usr/local"
while getopts "dp:f:" arg; do
case $arg in
d)
CMD="sudo rm -fr"
;;
p)
PREFIX=$arg
;;
f)
BOM_FILE=$arg
;;
esac
done
lsbom -f -l -s -pf ${BOM_FILE} \
| while read i; do
$CMD ${PREFIX}/${i}
done
$CMD ${PREFIX}/lib/node \
${PREFIX}/lib/node_modules \
${BOM_FILE}
Save it to file and run with:
将其保存到文件并运行:
# bash filename.sh
回答by Srini 7
I had to remove the following files too since brew complained in install later after manually removing all files.
我也必须删除以下文件,因为 brew 在手动删除所有文件后在安装中抱怨。
/usr/local/share/doc/node/gdbinit
/usr/local/share/systemtap/tapset/node.stp
and then do the following
然后执行以下操作
brew install node
brew link node
回答by Thomas Peters
The following worked after trial and error, and these directories were not writable so, I removed them and finally was able to get node & npm replaced.
经过反复试验,以下工作正常,并且这些目录不可写,因此,我删除了它们,最终能够替换 node & npm。
sudo rm -rf /usr/local/share/systemtap
sudo rm -rf /usr/local/share/doc/node
sudo rm -rf /usr/local/Cellar/node/9.11.1
brew install node
==> Downloading https://homebrew.bintray.com/bottles/node-9.11.1.high_sierra.bottle.tar.gz
Already downloaded: /Users/xxx/Library/Caches/Homebrew/node-9.11.1.high_sierra.bottle.tar.gz
==> Pouring node-9.11.1.high_sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
/usr/local/Cellar/node/9.11.1: 5,125 files, 49.7MB
node -v
v9.11.1
npm -v
5.6.0

