Debian 12 更换国内软件源

在 Debian 12 (即 Debian Bookworm) 中,如果你想使用国内的镜像来加速你的软件包下载,你可以通过修改/etc/apt/sources.list 文件来实现。

1. 备份原始的 sources.list

首先,备份你的原始 sources.list 文件,以防万一需要恢复。

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

2. 编辑 sources.list

使用文本编辑器编辑 /etc/apt/sources.list 文件,可以使用 nanovim

sudo nano /etc/apt/sources.list

3. 更换软件源

将文件中的内容替换为对应的镜像源。以下是一些常用的镜像源配置:

清华源:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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/ 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

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware

4. 更新软件包列表

更新你的软件包列表以使用新的镜像源。

sudo apt update

5. 清理缓存(可选)

如果你之前已经安装了一些软件包,并且想要清理旧的缓存数据,可以运行:

sudo apt clean

6. 升级软件包(可选)

最后,如果你想升级所有已安装的软件包到最新版本,可以运行:

sudo apt upgrade