Sources
使用 testing 版本
| 文件 | 功能 | 结果 |
|---|---|---|
/etc/apt/sources.list.d/debian.sources |
指定下载地址和分支 | 让 apt 知道去 testing 源获取包 |
/etc/apt/preferences.d/00default-release |
定义优先级策略 | 确保 apt 默认选择 testing 包,不会跑去 stable |
1. 编辑配置文件,编辑完成后请记得保存.
路径: /etc/apt/sources.list.d/debian.sources
# Debian Testing main repo
Types: deb
URIs: http://deb.debian.org/debian/
Suites: testing
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
# Debian Testing updates
Types: deb
URIs: http://deb.debian.org/debian/
Suites: testing-updates
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
# Debian Testing security
Types: deb
URIs: http://security.debian.org/debian-security/
Suites: testing-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg语法解释
-
Types: deb 指定仓库类型是二进制包(普通软件包),而不是源码包 deb-src。
-
URIs: 软件源的 URL,
http://deb.debian.org/debian/是官方推荐的全球镜像地址,支持 CDN 加速。 -
Suites: testing 指定分支是
testing,意味着跟随未来 Debian 14(Forky)的滚动更新。 -
Components: 仓库组件:
-
main→ 自由软件 -
contrib→ 自由软件 + 依赖非自由部分 -
non-free→ 非自由软件(如专有驱动) -
non-free-firmware→ Debian 12+ 引入的新分类,主要存放固件文件
-
-
Signed-By: 指定验证签名的 GPG 密钥文件路径,确保仓库来源可信。
# Debian Testing updates
...
Suites: testing-updates
...
# Debian Testing security
...
Suites: testing-security
...-
testing-updates 主要包含 testing 分支的紧急 bug 修复或小版本更新。
-
testing-security 由 Debian 安全团队维护的 security 仓库,用于推送安全更新。
总结
debian.sources 决定了 APT 从哪些仓库下载包,让系统源始终指向 testing、testing-updates 和 testing-security。
路径: /etc/apt/preferences.d/00default-release
Package: *
Pin: release a=testing
Pin-Priority: 900语法解释
-
Package: * 作用于所有软件包,不限范围。
-
Pin: release a=testing
release a=testing表示匹配所有属于 testing 分支 的包。 -
Pin-Priority: 900 设置
testing仓库优先级为 900。
APT 优先级规则
| 优先级范围 | 行为 |
|---|---|
| <0 | 禁止安装 |
| 1-99 | 只有手动指定才会安装 |
| 100-499 | 不会主动升级,但保持已安装状态 |
| 500 | 默认优先级(适用于当前稳定版本) |
| >500 | 优先选择这个版本 |
| 1000+ | 即使需要降级,也强制安装 |
900 的效果:
-
默认总是选择
testing仓库的包 -
但不会盲目覆盖你手动锁定版本的包
-
保证系统滚动升级保持
testing
2. 更新索引 & 升级系统
apt update && apt full-upgrade使用脚本: 创建&检测 Apt Source - testing 版本
1. 创建脚本
使用下面命令创建脚本:
vi /usr/local/bin/check-debian-branch.sh脚本内容:
提示
贴上脚本内容后,请记得保存
#!/bin/bash
# Check Debian branch and switch to testing if needed
SOURCES_FILE="/etc/apt/sources.list.d/debian.sources"
PREF_FILE="/etc/apt/preferences.d/00default-release"
echo "正在检查当前 Debian 分支..."
CURRENT_BRANCH=$(grep -E "^Suites:" "$SOURCES_FILE" | awk '{print $2}' | head -n 1)
if [[ "$CURRENT_BRANCH" == "testing" ]]; then
echo "✅ 当前系统已经是 Debian testing 分支。"
exit 0
else
echo "⚠ 当前系统分支为: $CURRENT_BRANCH"
read -rp "是否切换到 Debian testing 分支? (Y/N): " CONFIRM
if [[ "$CONFIRM" =~ ^[Yy]$ ]]; then
echo "正在切换到 Debian testing 分支..."
# 写入 sources.list.d/debian.sources
cat <<EOF | sudo tee "$SOURCES_FILE" > /dev/null
# Debian Testing main repo
Types: deb
URIs: http://deb.debian.org/debian/
Suites: testing
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
# Debian Testing updates
Types: deb
URIs: http://deb.debian.org/debian/
Suites: testing-updates
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
# Debian Testing security
Types: deb
URIs: http://security.debian.org/debian-security/
Suites: testing-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF
# 写入 pinning
sudo mkdir -p /etc/apt/preferences.d
cat <<EOF | sudo tee "$PREF_FILE" > /dev/null
Package: *
Pin: release a=testing
Pin-Priority: 900
EOF
echo "🔄 更新软件包索引..."
sudo apt update
echo "✅ 系统已切换为 Debian testing 分支。"
else
echo "❌ 已取消切换操作。"
fi
fi注释
这个脚本会检测 /etc/apt/sources.list.d/debian.sources中的内容,如果不包含testing,会创建下面两个文件:
查看 /etc/apt/sources.list.d/debian.sources
路径:
/etc/apt/sources.list.d/debian.sources内容:
# Debian Testing main repo
Types: deb
URIs: http://deb.debian.org/debian/
Suites: testing
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
# Debian Testing updates
Types: deb
URIs: http://deb.debian.org/debian/
Suites: testing-updates
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
# Debian Testing security
Types: deb
URIs: http://security.debian.org/debian-security/
Suites: testing-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
查看 /etc/apt/preferences.d/00default-release
路径:
/etc/apt/preferences.d/00default-release内容:
Package: *
Pin: release a=testing
Pin-Priority: 9002. 赋予执行权限
chmod +x /usr/local/bin/check-debian-branch.sh3. 运行
bash check-debian-branch.sh