Skip to content

卸载 fnm

如果你需要卸载 fnm,请按照以下步骤操作。

快速卸载

使用卸载脚本

fnm 提供了便捷的卸载脚本:

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

该脚本会自动:

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

手动卸载

如果卸载脚本无法正常工作,可以手动卸载。

步骤 1:删除 fnm 目录

fnm 默认将所有文件存储在 ~/.fnm 目录:

bash
rm -rf ~/.fnm

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

根据安装方式,fnm 二进制文件可能位于不同位置:

bash
# Homebrew 安装
brew uninstall fnm

# 手动安装(检查常见位置)
rm -f /usr/local/bin/fnm
rm -f ~/.local/bin/fnm
rm -f ~/bin/fnm

步骤 3:清理 Shell 配置

从 Shell 配置文件中移除 fnm 相关配置:

bash
# 编辑 ~/.bashrc,删除以下行
eval "$(fnm env --use-on-cd)"
bash
# 编辑 ~/.zshrc,删除以下行
eval "$(fnm env --use-on-cd)"
bash
# 编辑 ~/.config/fish/config.fish,删除以下行
fnm env --use-on-c | source
powershell
# 编辑 $PROFILE,删除以下行
fnm env --use-on-cd | Out-String | Invoke-Expression

步骤 4:重新加载 Shell

bash
# Bash
source ~/.bashrc

# Zsh
source ~/.zshrc

# Fish
source ~/.config/fish/config.fish

# PowerShell
. $PROFILE

各平台卸载指南

macOS

bash
# Homebrew 安装
brew uninstall fnm
rm -rf ~/.fnm

# 删除 Shell 配置中的 fnm 相关行

Windows

使用 winget

powershell
winget uninstall Schniz.fnm

使用 Scoop

powershell
scoop uninstall fnm

使用 Chocolatey

powershell
choco uninstall fnm

手动删除

  1. 删除 fnm 目录:%USERPROFILE%\.fnm
  2. 从 PATH 中移除 fnm 路径
  3. 清理 PowerShell 配置文件

Linux

bash
# 删除 fnm 目录
rm -rf ~/.fnm

# 删除二进制文件(根据安装位置)
rm -f /usr/local/bin/fnm
rm -f ~/.local/bin/fnm

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

保留 Node.js 版本

如果你想保留已安装的 Node.js 版本,可以在卸载前备份:

bash
# 查看 fnm 目录结构
ls -la ~/.fnm

# 备份 node 版本(如果需要)
cp -r ~/.fnm/node-versions ~/node-backup

卸载后验证

确认 fnm 已完全卸载:

bash
# 应该输出 "command not found" 或类似错误
fnm --version

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

常见问题

卸载后 Shell 启动报错

如果在卸载后 Shell 启动时报错,请检查配置文件中是否还有 fnm 相关代码。

PATH 中仍有 fnm 路径

检查并编辑 Shell 配置文件,移除所有 fnm 相关的 PATH 设置。

想重新安装 fnm

卸载后可以随时重新安装 fnm:

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

# Windows
winget install Schniz.fnm

相关链接