前言
本文介绍如何完全干净地卸载 OpenClaw,包括停止服务、删除配置、清理环境变量等步骤。
第一步:运行官方清理命令
在卸载前,先运行 OpenClaw 官方提供的清理命令,清理内部状态。
运行官方清理命令。
openclaw cleanup
停止网关。
openclaw gateway stop
第二步:停止并卸载 OpenClaw 服务
禁用开机自启(如果设置了)。
systemctl --user disable openclaw-gateway.service
删除 systemd 服务文件。
先删除主服务文件。
rm -f ~/.config/systemd/user/openclaw-gateway.service
删除 override 目录。
rm -rf ~/.config/systemd/user/openclaw-gateway.service.d
删除备份文件。
rm -f ~/.config/systemd/user/openclaw-gateway.service.bak
重新加载 systemd。
systemctl --user daemon-reload
第三步:卸载全局 npm 包
卸载 OpenClaw。
sudo npm uninstall -g openclaw
清理 npm 缓存。
npm cache clean --force
第四步:删除配置文件和数据
删除 OpenClaw 主配置目录(包含飞书、模型等所有配置)。
rm -rf ~/.openclaw
删除可能残留的日志。
rm -rf ~/.openclaw_logs
删除其他可能的隐藏目录。
rm -rf ~/.config/openclaw
rm -rf ~/.cache/openclaw
删除 npm 全局安装记录(可选)。
rm -rf ~/.npm-global/lib/node_modules/openclaw
注意:删除 ~/.openclaw 会清除所有配置、会话、记忆。如需保留,先执行备份命令。
第五步:清理环境变量
检查以下所有 shell 配置文件,删除 OpenClaw 相关行。
需要检查的文件包括:.bashrc、.zshrc、.bash_profile、.profile、Fish 配置文件。
每个文件单独检查。
查看每个文件是否有残留。
cat ~/.bashrc
cat ~/.zshrc
cat ~/.bash_profile
cat ~/.profile
cat ~/.config/fish/config.fish
用 grep 搜索 OpenClaw 相关行。
grep -i openclaw ~/.bashrc
grep -i openclaw ~/.zshrc
grep -i openclaw ~/.bash_profile
grep -i openclaw ~/.profile
需要删除的行示例:
打开文件编辑。
nano ~/.bashrc
找到并删除这两行。
# OpenClaw Completion
source "/home/pi/.openclaw/completions/openclaw.bash"
说明:如果还有 npm 全局路径相关的行(通常是包含 .npm-global 的 PATH 设置),看系统里有没有其他全局 npm 包,没有的话可以一起删掉。
保存后重新加载。
source ~/.bashrc
第六步:清理其他残留(桌面端)
如果你在桌面 Linux 或 Mac 上使用 OpenClaw,还需要检查以下位置。
清理 desktop 文件。
rm -f ~/.local/share/applications/openclaw.desktop
rm -f ~/.local/share/applications/openclaw-gateway.desktop
Mac 清理 LaunchAgents。
rm -f ~/Library/LaunchAgents/com.openclaw.gateway.plist
rm -rf ~/Library/Application\ Support/OpenClaw
Linux 清理桌面入口。
rm -f ~/.local/share/applications/openclaw*.desktop
第七步:检查残留进程
卸载完成后,检查是否还有 OpenClaw 相关进程在运行。
ps aux | grep -i openclaw
如果有残留进程,手动终止。
pkill -f openclaw
killall openclaw
第八步:验证卸载
执行以下命令确认没有残留:
检查 openclaw 命令是否还存在。
which openclaw
检查版本命令是否报错。
openclaw --version
检查配置目录是否已删除。
ls ~/.openclaw
检查配置文件是否已删除。
ls ~/.config/openclaw
检查缓存目录是否已删除。
ls ~/.cache/openclaw
常见问题
Q: 卸载后重新安装会丢失数据吗?
A: 是的,删除 ~/.openclaw 后所有配置、会话历史、记忆都会丢失。请在卸载前按需备份。
Q: npm 包卸载失败怎么办?
A: 使用 sudo 强制卸载。
sudo npm uninstall -g openclaw --force
Q: 环境变量清理后需要重新登录才生效?
A: 执行对应配置文件的 source 命令即可立即生效,无需重新登录。
Q: 如何确认所有配置文件都删干净了?
A: 用以下命令全局搜索。如果以上命令都没有输出,说明清理干净了。
grep -r "openclaw" ~/.bashrc ~/.zshrc ~/.profile ~/.config
find ~/.config ~/.local ~/Library -name "*openclaw*"
评论 (0)
暂无评论