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路径: /etc/apt/preferences.d/00default-release
Package: *
Pin: release a=testing
Pin-Priority: 9002. 更新索引 & 升级系统
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,会创建下面两个文件:
2. 赋予执行权限
chmod +x /usr/local/bin/check-debian-branch.sh3. 运行
bash check-debian-branch.sh