目录
Debian Bookworm 是 Debian 12 的代号,属于当前的稳定版(stable)。以下是针对 Debian Bookworm 更换为国内源的可执行代码,以阿里云源为例:
可执行代码
在 Termux 中运行以下代码,将 Debian Bookworm 的源替换为阿里云源:
proot-distro login debian -- bash -c '
# 备份原有源列表
cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 替换为阿里云源
cat <<EOF > /etc/apt/sources.list
deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware
deb-src http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware
deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware
deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware
EOF
# 更新软件包列表
apt update
# 升级已安装的软件包(可选)
apt upgrade -y
'
代码说明
备份原有源列表:
- 将原有的
/etc/apt/sources.list
文件备份为/etc/apt/sources.list.bak
,以便需要时恢复。
- 将原有的
替换为阿里云源:
- 使用
cat
命令将阿里云的源配置写入/etc/apt/sources.list
。 包含以下部分:
main
:官方支持的免费软件。contrib
:依赖于非自由软件的免费软件。non-free
:非自由软件。non-free-firmware
:非自由的固件(Debian 12 新增的分类)。
- 包含
bookworm
(稳定版)、bookworm-security
(安全更新)和bookworm-updates
(常规更新)三个部分。
- 使用
更新软件包列表:
- 运行
apt update
更新软件包列表。
- 运行
升级已安装的软件包:
- 运行
apt upgrade -y
升级所有已安装的软件包(可选)。
- 运行
其他国内源
如果您想使用其他国内源,可以将阿里云的地址替换为以下地址之一:
清华大学源
cat <<EOF > /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
EOF
中科大源
cat <<EOF > /etc/apt/sources.list
deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
EOF
验证源是否生效
运行以下命令查看源是否生效:
apt update
如果显示从国内源下载软件包列表,说明源已成功更换。
恢复原有源
如果需要恢复原有源,可以运行以下命令:
cp /etc/apt/sources.list.bak /etc/apt/sources.list
apt update
总结
- 以上代码适用于 Debian Bookworm(Debian 12)。
- 替换为国内源后,软件包下载速度将显著提升。
- 如果需要使用其他国内源,只需替换源地址即可。
最新回复