本文最后更新于 2025-08-19,文章内容可能已经过时。

本文将指导如何升级 **Debian 12 Bookworm** 到 **Debian 13 Trixie**。  
相关教程:[Debian 11 Bullseye 升级 Debian 12 Bookworm](https://u.sb/debian-upgrade-12)。

## ⚠️ 准备工作(必看)

- **备份!备份!备份!**  
  云主机请打快照,物理机请用 `rsync`、`borg`、`timeshift` 等备份系统盘。

- **OpenVZ 6 / LXC** 无法升级,因为他们没有独立内核。

- **全程 root**  
  ```bash
  sudo -i

1️⃣ 先把 12 升到最新

apt update
apt upgrade -y
apt full-upgrade -y
apt autoclean
apt autoremove -y

如果更新了 可以重启一次

reboot

2️⃣ 修改软件源(bookworm → trixie)

🔹 传统 One-Line 格式(多数机器)

bash

复制

sed -i 's/bookworm/trixie/g' /etc/apt/sources.list
sed -i 's/bookworm/trixie/g' /etc/apt/sources.list.d/*.list
sed -i 's/bookworm/trixie/g' /etc/apt/sources.list.d/*.sources 2>/dev/null || true

完成后 /etc/apt/sources.list 应类似:

Text

复制

deb https://deb.debian.org/debian trixie main contrib non-free non-free-firmware
deb https://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
deb https://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmware

国内服务器可替换为清华镜像:

Text

复制

mirrors.tuna.tsinghua.edu.cn

🔹 DEB822 格式(推荐)

新建或覆盖 /etc/apt/sources.list.d/debian.sources

Tex

复制

Types: deb
URIs: https://deb.debian.org/debian
Suites: trixie trixie-updates trixie-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb
URIs: https://security.debian.org/debian-security
Suites: trixie-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

然后删除旧文件:

bash

复制

rm -f /etc/apt/sources.list


3️⃣ 真正开始升级

bash

复制

apt update
apt upgrade -y
apt full-upgrade -y
  • libc6 重启服务提示:

    • 个人/测试机 → 选 Yes

    • 生产机 → 选 No(稍后手动重启)

  • 配置文件冲突(例如 sshd_config)

    • D 查看差异 → 合并或保留 → 回车继续


4️⃣ 清理 & 重启

bash

复制

apt autoclean
apt autoremove -y
reboot

5️⃣ 验证结果

bash

复制

cat /etc/debian_version      # 13.0
lsb_release -a               # Debian GNU/Linux 13 (trixie)
uname -a                     # 6.12.38+deb13-cloud-amd64 或更新

6️⃣ 安装编译环境(可选)

bash

复制

apt install -y build-essential \
  libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
  libsqlite3-dev libncurses5-dev libncursesw5-dev \
  tk-dev libffi-dev liblzma-dev

7️⃣ 一键速查表

表格

复制

操作

命令

修复依赖

apt --fix-broken install

查看版本

cat /etc/debian_version && lsb_release -a

查看升级包

apt list --upgradable

手动回滚

救援模式 → chrootapt install -f && update-grub


恭喜,你已经成功升级到 Debian 13 Trixie
欢迎把本文分享给更多需要的小伙伴。