Javascript 如何完全卸载 Node.js,并从头开始重新安装 (Mac OS X)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11177954/
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 completely uninstall Node.js, and reinstall from beginning (Mac OS X)
提问by Dominic Tancredi
My version of node is always v0.6.1-pre even after I install brew node and NVM install v0.6.19.
即使在我安装了 brew node 和 NVM 安装 v0.6.19 之后,我的 node 版本也始终是 v0.6.1-pre。
My node version is:
我的节点版本是:
node -v
v0.6.1-pre
NVM says this (after I install a version of node for the first time in one bash terminal):
NVM 是这样说的(在我第一次在一个 bash 终端中安装一个 node 版本之后):
nvm ls
v0.6.19
current: v0.6.19
But when I restart bash, this is what I see:
但是当我重新启动 bash 时,我看到的是:
nvm ls
v0.6.19
current: v0.6.1-pre
default -> 0.6.19 (-> v0.6.19)
So where is this phantom node 0.6.1-pre version and how can I get rid of it? I'm trying to install libraries via NPM so that I can work on a project.
那么这个 phantom node 0.6.1-pre 版本在哪里,我该如何摆脱它?我正在尝试通过 NPM 安装库,以便我可以处理项目。
I tried using BREW to update before NVM, using brew update
and brew install node
.
I've tried deleting the "node" directory in my /usr/local/include
and the "node" and "node_modules" in my /usr/local/lib
.
I've tried uninstalling npm and reinstalling it following theseinstructions.
我尝试在 NVM 之前使用 BREW 进行更新,使用brew update
和brew install node
。我已经尝试删除我的“节点”目录/usr/local/include
以及我的/usr/local/lib
. 我已经尝试按照这些说明卸载 npm 并重新安装它。
All of this because I was trying to update an older version of node to install the "zipstream" library. Now there's folders in my users directory, and the node version STILL isn't up to date, even though NVM says it's using 0.6.19.
所有这一切都是因为我试图更新旧版本的节点以安装“zipstream”库。现在我的用户目录中有文件夹,节点版本仍然不是最新的,即使 NVM 说它使用的是 0.6.19。
Ideally, I'd like to uninstall nodejs, npm, and nvm, and just reinstall the entire thing from scratch on my system.
理想情况下,我想卸载 nodejs、npm 和 nvm,然后在我的系统上从头开始重新安装整个东西。
回答by Dominic Tancredi
Apparently, there was a /Users/myusername/local
folder that contained a include
with node
and lib
with node
and node_modules
. How and why this was created instead of in my /usr/local
folder, I do not know.
显然,有一个/Users/myusername/local
包含文件夹include
与node
和lib
与node
和node_modules
。/usr/local
我不知道这是如何以及为什么在我的文件夹中而不是在我的文件夹中创建的。
Deleting these local references fixed the phantom v0.6.1-pre. If anyone has an explanation, I'll choose that as the correct answer.
删除这些本地引用修复了 phantom v0.6.1-pre。如果有人有解释,我会选择它作为正确答案。
EDIT:
编辑:
You may need to do the additional instructions as well:
您可能还需要执行其他说明:
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
which is the equivalent of (same as above)...
这相当于(同上)...
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp
or (same as above) broken down...
或(同上)分解...
To completely uninstall node + npm is to do the following:
要完全卸载 node + npm 是执行以下操作:
- go to /usr/local/liband delete any nodeand node_modules
- go to /usr/local/includeand delete any nodeand node_modulesdirectory
- if you installed with brew install node, then run brew uninstall nodein your terminal
- check your Home directory for any localor libor includefolders, and delete any nodeor node_modulesfrom there
- go to /usr/local/binand delete any nodeexecutable
- 转到/usr/local/lib并删除任何节点和node_modules
- 转到/usr/local/include并删除任何节点和node_modules目录
- 如果您使用brew install node 安装,则在终端中运行brew uninstall node
- 检查您的主目录中是否有任何本地或lib或包含文件夹,并从那里删除任何节点或node_modules
- 转到/usr/local/bin并删除任何节点可执行文件
You may also need to do:
您可能还需要执行以下操作:
sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d
Additionally, NVM modifies the PATH variable in $HOME/.bashrc
, which must be reverted manually.
此外,NVM 修改了 PATH 变量$HOME/.bashrc
,必须手动恢复。
Then download nvmand follow the instructions to install node. The latest versions of node come with npm, I believe, but you can also reinstall that as well.
然后下载nvm并按照说明安装 node。我相信最新版本的 node 带有npm,但您也可以重新安装它。
回答by lfender6445
For brew users, OSX:
对于 brew 用户,OSX:
To remove:
去除:
brew uninstall node;
# or `brew uninstall --force node` which removes all versions
brew cleanup;
rm -f /usr/local/bin/npm /usr/local/lib/dtrace/node.d;
rm -rf ~/.npm;
To install:
安装:
brew install node;
which node # => /usr/local/bin/node
export NODE_PATH='/usr/local/lib/node_modules' # <--- add this ~/.bashrc
You can run brew info node
for more details regarding your node installs.
您可以运行brew info node
以获取有关节点安装的更多详细信息。
consider using NVM instead of brew
考虑使用 NVM 而不是 brew
NVM (node version manager) is a portable solution for managing multiple versions of node
NVM(节点版本管理器)是一个可移植的解决方案,用于管理节点的多个版本
https://github.com/nvm-sh/nvm
https://github.com/nvm-sh/nvm
> nvm uninstall v4.1.0
> nvm install v8.1.2
> nvm use v8.1.2
> nvm list
v4.2.0
v5.8.0
v6.11.0
-> v8.1.2
system
you can use this with AVNto automatically switch versions as you hop between different projects with different node dependencies.
当您在具有不同节点依赖项的不同项目之间跳转时,您可以将其与 AVN一起使用以自动切换版本。
回答by DaveyJake
I know this post is a little dated but just wanted to share the commands that worked for me in Terminal when removing Node.js.
我知道这篇文章有点过时,但只是想分享删除 Node.js 时在终端中对我有用的命令。
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
UPDATE: 23 SEP 2016
更新: 23 SEP 2016
If you're afraid of running these commands...
如果你害怕运行这些命令......
Thanks to jguix
for this quick tutorial
.
First, create an intermediate file:
首先,创建一个中间文件:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom >> ~/filelist.txt
Manually review your file (located in your Home
folder)
手动查看您的文件(位于您的Home
文件夹中)
~/filelist.txt
Then delete the files:
然后删除文件:
cat ~/filelist.txt | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
For 10.10.5 and above
对于 10.10.5 及更高版本
Thanks Lenar Hoyt
谢谢 Lenar Hoyt
Gist Comment Source:gistcomment-1572198
要点评论来源:gistcomment-1572198
Original Gist:TonyMtz/d75101d9bdf764c890ef
原始要点:TonyMtz/d75101d9bdf764c890ef
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
回答by Pedro Polonia
On Mavericks I install it from the node pkg (from nodejs site) and I uninstall it so I can re-install using brew. I only run 4 commands in the terminal:
在 Mavericks 上,我从节点 pkg(来自 nodejs 站点)安装它并卸载它,以便我可以使用 brew 重新安装。我只在终端中运行 4 个命令:
sudo rm -rf /usr/local/lib/node_modules/npm/
brew uninstall node
brew doctor
brew cleanup --prune-prefix
sudo rm -rf /usr/local/lib/node_modules/npm/
brew uninstall node
brew doctor
brew cleanup --prune-prefix
If there is still a node installation, repeat step 2. After all is ok, I install using brew install node
如果还有节点安装,重复第2步。 一切OK后,我安装使用 brew install node
回答by Johel Alvarez
First:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
go to
/usr/local/lib
and delete any node and node_modulescd /usr/local/lib sudo rm -rf node*
go to
/usr/local/include
and delete any node and node_modules directorycd /usr/local/include sudo rm -rf node*
if you installed with
brew install node
, then runbrew uninstall node
in your terminalbrew uninstall node
check your Home directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there
go to /usr/local/bin and delete any node executable
cd /usr/local/bin sudo rm -rf /usr/local/bin/npm ls -las
You may need to do the additional instructions as well:
sudo rm -rf /usr/local/share/man/man1/node.1 sudo rm -rf /usr/local/lib/dtrace/node.d sudo rm -rf ~/.npm
第一的:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
总结一下,完全卸载 node + npm 的最佳方法(我发现)是执行以下操作:
转到
/usr/local/lib
并删除任何节点和 node_modulescd /usr/local/lib sudo rm -rf node*
转到
/usr/local/include
并删除任何节点和 node_modules 目录cd /usr/local/include sudo rm -rf node*
如果您安装了
brew install node
,则brew uninstall node
在您的终端中运行brew uninstall node
检查您的主目录中是否有任何“local”或“lib”或“include”文件夹,并从那里删除任何“node”或“node_modules”
转到 /usr/local/bin 并删除任何节点可执行文件
cd /usr/local/bin sudo rm -rf /usr/local/bin/npm ls -las
您可能还需要执行其他说明:
sudo rm -rf /usr/local/share/man/man1/node.1 sudo rm -rf /usr/local/lib/dtrace/node.d sudo rm -rf ~/.npm
Source: tonyMtz
资料来源:tonyMtz
回答by Anja Ishmukhametova
downgrade node to 0.10.36
将节点降级到 0.10.36
sudo npm cache clean -f
sudo npm install -g n
sudo n 0.10.36
upgrade node to stable v
将节点升级到稳定版 v
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
回答by Big McLargeHuge
I'm not sure if it's because I had an old version (4.4.5), or if it's because I used the official installer, but most of the files referenced in other answers didn't exist on my system. I only had to remove the following:
我不确定是因为我有一个旧版本(4.4.5),还是因为我使用了官方安装程序,但其他答案中引用的大多数文件在我的系统上都不存在。我只需要删除以下内容:
~/.node-gyp
~/.node_repl_history
/usr/local/bin/node
/usr/local/bin/npm
/usr/local/include/node
/usr/local/lib/dtrace/node.d
/usr/local/lib/node_modules
/usr/local/share/doc/node
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp
I decided to keep ~/.npm
because I was planning on reinstalling Node with Homebrew.
我决定保留,~/.npm
因为我打算用 Homebrew 重新安装 Node。
回答by Dary
I have summarized the existing answers and made sure Node js is COMPLETELY ERASEDalong with NPM.
我已经总结了现有的答案,并确保 Node js与 NPM 一起完全删除。
brew uninstall node
which node
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/lib/node_modules/npm/
brew doctor
brew cleanup --prune-prefix
brew uninstall node
which node
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/lib/node_modules/npm/
brew doctor
brew cleanup --prune-prefix
Lines to copy to terminal:
复制到终端的行:
brew uninstall node;
which node;
sudo rm -rf /usr/local/bin/node;
sudo rm -rf /usr/local/lib/node_modules/npm/;
brew doctor;
brew cleanup --prune-prefix;
回答by Rajiv Singh
Delete?node?and/or?node_modules?from?/usr/local/lib
ex code: cd /usr/local/lib sudo rm -rf node sudo rm -rf node_modules
Delete?node?and/or?node_modules?from?/usr/local/include
- Delete?node,?node-debug, and?node-gyp?from?/usr/local/bin
- Delete?.npmrc?from your home directory (these are your npm settings, don't delete this if you plan on re-installing Node right away)
- Delete?.npm?from your home directory
- Delete?.node-gyp?from your home directory
- Delete?.node_repl_history?from your home directory
- Delete?node*?from?/usr/local/share/man/man1/
- Delete?npm*?from?/usr/local/share/man/man1/
- Delete?node.d?from?/usr/local/lib/dtrace/
- Delete?node?from?/usr/local/opt/local/bin/
- Delete?node?from?/usr/local/opt/local/include/
- Delete?node_modules?from?/usr/local/opt/local/lib/
- Delete?node?from?/usr/local/share/doc/
- Delete?node.stp?from?/usr/local/share/systemtap/tapset/
删除?node?和/或?node_modules?from?/usr/local/lib
ex code: cd /usr/local/lib sudo rm -rf node sudo rm -rf node_modules
删除?node?和/或?node_modules?from?/usr/local/include
- 删除?node,?node-debug, and?node-gyp?from?/usr/local/bin
- 从你的主目录删除?.npmrc?(这些是你的 npm 设置,如果你打算立即重新安装 Node,请不要删除它)
- 从您的主目录中删除?.npm?
- 从您的主目录中删除?.node-gyp?
- 从您的主目录中删除?.node_repl_history?
- Delete?node*?from?/usr/local/share/man/man1/
- 删除?npm*?from?/usr/local/share/man/man1/
- 删除?node.d?from?/usr/local/lib/dtrace/
- Delete?node?from?/usr/local/opt/local/bin/
- Delete?node?from?/usr/local/opt/local/include/
- 删除?node_modules?from?/usr/local/opt/local/lib/
- 删除?节点?从?/usr/local/share/doc/
- 删除?node.stp?from?/usr/local/share/systemtap/tapset/
回答by Inês Gomes
Worked for me.
为我工作。
$node --version
v11.1.0
$nvm deactivate
$nvm uninstall v11.1.0