系统升级与紧急降级¶
创建于:2025-08-14 最后更新:2025-09-17
简介说明¶
Debian 13 (trixie)1 于近期发布。
本节将会记录系统全面更新的实践,并附加对单个软件包(pip3
)进行紧急降级操作的演示。因为这些操作本身就很危险,因此不提供“故障排查”内容用于参考。建议在开始前请做好数据备份,出问题了直接重装系统。
警告
本页面只专注于全面更新与紧急降级的 操作本身,不去考虑新发布系统的稳定性2,是否使用新系统请自行判断。
前置条件¶
- 系统要求:Debian 12 (bookworm)
- 相关工具:
dpkg
、apt-get
、apt-mark
、apt-cache
、apt
、tmux
- 数据源:中科大镜像软件源、中科大镜像软件安全更新源
全面更新¶
如果是远程连接,建议在 tmux
中运行下方脚本,防止网络波动导致更新失败。脚本思路如下:
-
十分重要的 前期安全检查工作(来自 Release Notes for Debian 13 的建议):
进行全面更新前后你需要做的事情
-
使用脚本前:手动执行
apt list '?narrow(?installed, ?not(?origin(Debian)))'
命令,处理可能会出问题的包。 -
更新系统后:手动执行
apt purge '~o'
、apt purge '~c'
和apt autoremove
命令,清理多余的包和配置文件。
- 检查当前系统版本:确定你正在从 Debian 12 升级到 Debian 13。
- 使用
tar
和dpkg
工具备份重要数据。 - 使用
find
、dpkg
和apt-mark
工具进行前期检查。
-
-
修改 APT 系统数据源为中科大镜像软件源与中科大镜像软件安全更新源。
- 开始执行更新系统的操作,更新后重启系统。
紧急降级¶
如果你在生产环境中,发现新版本的 pip3
有 bug,需要回退,下面提供了一个具体实践用于演示如何对其降级。操作前请仔细阅读文档。这个操作很危险,建议结合 apt-cache
和 apt policy
工具严谨地使用这个技术。
实际使用这个技术之前你必须知道的事
降级在 Debian 设计上就不被官方支持。该操作只建议用于回退通过 apt-pinning
临时升级的 非核心、低依赖 软件。其他非常规、高风险的用法,极易产生系统依赖链的断裂,造成难以挽回的后果。
对于重要系统,你应当备份所有重要数据,从零开始重新安装一个新的系统。
先确认降级前的系统状态与 pip3
的版本:
- 文件
/etc/apt/preferences
的内容如下所示。 - 使用
apt policy
工具可以检查当前软件包的选择优先级。
Explanation: Date Created: 2025-08-10 | Date Modified: 2025-08-14
Explanation: Install only the most recent trixie version of pip3
Package: python3-pip
Pin: release n=trixie*
Pin-Priority: 700
Explanation: Install package if it is selected for installation
Explanation: and no version of the package is already installed
Package: *
Pin: release n=trixie*
Pin-Priority: 50
$ sudo apt policy python3-pip # Check the priority of pip3
python3-pip:
Installed: 25.1.1+dfsg-1
Candidate: 25.1.1+dfsg-1
Version table:
*** 25.1.1+dfsg-1 700
50 https://mirrors.ustc.edu.cn/debian trixie/main amd64 Packages
100 /var/lib/dpkg/status
23.0.1+dfsg-1 500
500 https://mirrors.ustc.edu.cn/debian bookworm/main amd64 Packages
$ pip3 -V # Check the version of pip3
pip 25.1.1 from /usr/lib/python3/dist-packages/pip (python 3.11)
开始降级操作¶
接下来我们开始进行版本回退操作:
-
先修改
/etc/apt/preferences
的内容: -
执行
sudo apt update
后使用sudo apt full-upgrade
命令开始降级,此时屏幕的输出如下(略去无关内容):警告
请在每次修改好
/etc/apt/preferences
文件内容后,都执行一次执行sudo apt update
以应用配置。$ sudo apt update && sudo apt full-upgrade ... The following packages will be DOWNGRADED: python3-pip 0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded. ... Do you want to continue? [Y/n] y # Enter `y' to continue. Get:1 https://mirrors.ustc.edu.cn/debian bookworm/main amd64 python3-pip all 23.0.1+dfsg-1 [1,325 kB] Fetched 1,325 kB in 1s (1,883 kB/s) dpkg: warning: downgrading python3-pip from 25.1.1+dfsg-1 to 23.0.1+dfsg-1 (Reading database ... 41913 files and directories currently installed.) Preparing to unpack .../python3-pip_23.0.1+dfsg-1_all.deb ... Unpacking python3-pip (23.0.1+dfsg-1) over (25.1.1+dfsg-1) ... ...
-
上述命令执行完成后,你可以检查你的
pip3
版本:
附录:参考与链接¶
- APT pinning 参考:
man 5 apt_preferences