Skip to content

在 Ubuntu 上卸载 fnm

本指南详细介绍如何在 Ubuntu 系统上完全卸载 fnm。

快速卸载

使用卸载脚本

bash
curl -fsSL https://fnm.vercel.app/uninstall | bash

该脚本会:

  • 删除 fnm 二进制文件
  • 清理 ~/.fnm 目录
  • 提示你移除 Shell 配置中的 fnm 相关代码

手动卸载步骤

步骤 1:删除 fnm 目录

bash
rm -rf ~/.fnm

步骤 2:删除 fnm 二进制文件

根据安装方式,fnm 可能位于不同位置:

bash
# 如果使用 curl 脚本安装
rm -f ~/.fnm/fnm

# 如果手动安装到 /usr/local/bin
sudo rm -f /usr/local/bin/fnm

# 如果使用 Homebrew 安装
brew uninstall fnm

步骤 3:清理 Shell 配置

Bash

编辑 ~/.bashrc

bash
nano ~/.bashrc

删除以下行:

bash
eval "$(fnm env --use-on-cd)"
export PATH="$HOME/.fnm:$PATH"

重新加载:

bash
source ~/.bashrc

Zsh

编辑 ~/.zshrc

bash
nano ~/.zshrc

删除以下行:

bash
eval "$(fnm env --use-on-cd)"
export PATH="$HOME/.fnm:$PATH"

重新加载:

bash
source ~/.zshrc

步骤 4:清理环境变量

检查并清理相关环境变量:

bash
# 查看当前环境变量
env | grep FNM

# 如果有残留,编辑 Shell 配置文件移除

使用 apt 安装的 fnm

如果你通过 apt 安装了 fnm:

bash
# 查找包名
dpkg -l | grep fnm

# 卸载
sudo apt remove fnm
sudo apt autoremove

使用 Snap 安装的 fnm

如果你通过 Snap 安装:

bash
sudo snap remove fnm

清理 Node.js 版本

如果你想同时删除 fnm 管理的 Node.js 版本:

bash
# 删除所有 Node.js 版本
rm -rf ~/.fnm/node-versions

保留 Node.js 版本

如果你想保留已安装的 Node.js 版本:

bash
# 备份 Node.js 版本
cp -r ~/.fnm/node-versions ~/node-backup

# 或导出到系统路径
sudo cp -r ~/.fnm/node-versions/v20.10.0/installation /usr/local/node20
sudo ln -s /usr/local/node20/bin/node /usr/local/bin/node

验证卸载

bash
# 应该输出 "command not found"
fnm --version

# 检查目录是否已删除
ls ~/.fnm

# 检查 PATH 中是否还有 fnm
echo $PATH | grep fnm

常见问题

卸载后 Shell 启动慢

检查 Shell 配置文件中是否还有残留代码:

bash
grep -r "fnm" ~/.bashrc ~/.zshrc ~/.profile 2>/dev/null

node 命令找不到

卸载 fnm 后,如果没有其他 Node.js 安装:

bash
# 安装系统 Node.js
sudo apt update
sudo apt install nodejs npm

# 或重新安装 fnm
curl -fsSL https://fnm.vercel.app/install | bash

PATH 问题

如果 PATH 中仍有 fnm 相关路径:

bash
# 检查 PATH
echo $PATH

# 编辑 Shell 配置文件清理
nano ~/.bashrc  # 或 ~/.zshrc

重新安装

如果需要重新安装 fnm:

bash
curl -fsSL https://fnm.vercel.app/install | bash

# 配置 Shell
echo 'eval "$(fnm env --use-on-cd)"' >> ~/.bashrc
source ~/.bashrc

相关链接