温馨提示×

Debian如何卸载Nodejs

小樊
39
2026-07-15 03:53:11
栏目: 编程语言

在 Debian 上卸载 Node.js 的方法取决于你是用哪种方式安装的。下面按常见安装方式分别说明。


一、使用 apt 安装的 Node.js

1. 查看是否通过 apt 安装

dpkg -l | grep node

2. 卸载 Node.js

sudo apt remove nodejs

如果想同时删除配置文件:

sudo apt purge nodejs

3. 删除无用依赖

sudo apt autoremove

4. 确认是否卸载成功

node -v
npm -v

如果还能看到版本号,说明可能还有其他安装方式。


二、使用 nvm 安装的 Node.js(最常见)

1. 查看已安装版本

nvm ls

2. 卸载指定版本

nvm uninstall <version>

例如:

nvm uninstall 18

3. 移除 nvm 本身(可选)

编辑 ~/.bashrc~/.zshrc,删除 nvm 相关配置,然后:

rm -rf ~/.nvm

三、使用 NodeSource 安装的 Node.js

如果你是通过以下方式安装的:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install nodejs

卸载方式

sudo apt remove nodejs
sudo apt purge nodejs
sudo apt autoremove

删除 NodeSource 源(可选)

sudo rm /etc/apt/sources.list.d/nodesource.list
sudo apt update

四、通过二进制包(官方压缩包)手动安装

如果你解压了 node-vxx-linux-x64.tar.xz 并手动放到 /usr/local$HOME

1. 找到安装路径

which node

2. 删除相关目录

例如:

sudo rm -rf /usr/local/lib/nodejs
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/bin/npm

五、彻底清理 npm 缓存(可选)

npm cache clean --force
rm -rf ~/.npm
rm -rf ~/.node-gyp

推荐做法(✅ 最佳实践)

如果你只是想 干净重装 Node.js,推荐使用 nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install --lts

如果你愿意,可以告诉我:

  • 你当初是怎么安装的 Node.js?
  • Debian 版本(如 Debian 11 / 12)

我可以给你最安全、最干净的卸载方案

0