第一步:依然是防断网神装(Tmux/Screen)
# 安装并进入 tmux
sudo apt update && sudo apt install tmux -y && tmux
注:如果在更新过程中 SSH 掉线,重新连上后输入 tmux a 即可无缝回到更新界面。
第二步:检查 Debian 12 特有的软件源 (APT Sources)
deb http://deb.debian.org/debian/ bookworm main non-free-firmware contrib non-free
deb http://security.debian.org/debian-security bookworm-security main non-free-firmware contrib non-free
deb http://deb.debian.org/debian/ bookworm-updates main non-free-firmware contrib non-free
第三步:安全的“现代版”两步更新法
① 基础安全升级(不删包,不解决冲突)
sudo apt update
sudo apt upgrade --with-new-pkgs
关键安全提示:处理配置文件冲突 在升级过程中(尤其是 openssh-server 或 sshd),终端可能会弹窗问你是否用新版本覆盖现有的配置文件。 强烈建议选择:保持当前已安装的版本(通常是默认选项 N 或 Keep the local version currently installed)。如果直接覆盖,可能会导致你的自定义 SSH 端口、密钥登录失效,直接将你锁在服务器外面!
② 全面升级(处理核心依赖和内核)
sudo apt full-upgrade
第四步:清理与重启
1,清理卸载残留和孤立包:
sudo apt autoremove --purge -y
sudo apt clean
2,安全重启
# 检查是否真的需要重启(如果有该文件则需要)
[ -f /var/run/reboot-required ] && echo "需要重启"
# 执行重启
sudo reboot