475 字
2 分钟
Debian12 APT源配置
Debian 12 (bookworm) 默认的 deb.debian.org 走海外节点,国内访问速度感人。把 /etc/apt/sources.list 替换为阿里云或腾讯云镜像即可。
1. 备份原配置
$ mv /etc/apt/sources.list /etc/apt/sources.list.bakDebian 12 部分场景下源配置改放到
/etc/apt/sources.list.d/debian.sources(DEB822 新格式),如果sources.list是空的,需要去sources.list.d/下找文件改。
2. 阿里云源
$ cat > /etc/apt/sources.list <<EOFdeb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contribdeb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security maindeb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contribdeb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contribdeb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contribEOF3. 腾讯云源(备选)
$ cat > /etc/apt/sources.list <<EOFdeb https://mirrors.cloud.tencent.com/debian/ bookworm main non-free non-free-firmware contribdeb-src https://mirrors.cloud.tencent.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.cloud.tencent.com/debian-security/ bookworm-security maindeb-src https://mirrors.cloud.tencent.com/debian-security/ bookworm-security main
deb https://mirrors.cloud.tencent.com/debian/ bookworm-updates main non-free non-free-firmware contribdeb-src https://mirrors.cloud.tencent.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.cloud.tencent.com/debian/ bookworm-backports main non-free non-free-firmware contribdeb-src https://mirrors.cloud.tencent.com/debian/ bookworm-backports main non-free non-free-firmware contribEOF阿里云和腾讯云源二选一,不要同时启用,否则 apt 会处理重复包源浪费时间。
4. 四种仓库的作用
Debian 的 source.list 通常包含四组:
| 仓库 | 用途 |
|---|---|
bookworm | 主仓库,稳定版正式包 |
bookworm-security | 安全更新(安全相关漏洞补丁) |
bookworm-updates | 非紧急更新(功能修复、稳定性提升) |
bookworm-backports | 从 testing 回移的较新版本(自愿启用) |
main / contrib / non-free / non-free-firmware 分别对应自由软件、依赖非自由软件的自由软件、非自由软件、非自由固件。Debian 12 开始 non-free-firmware 是独立组件,必须显式启用才能装 Wi-Fi、显卡等固件。
5. 更新源
$ apt update$ apt upgrade -y6. 常见问题
| 现象 | 处理 |
|---|---|
apt update 报 NO_PUBKEY | 缺少 GPG 公钥,apt install -y debian-archive-keyring |
| HTTPS 仓库报证书错误 | apt install -y ca-certificates 或暂时改为 http:// |
| 改完仍走旧地址 | DEB822 新格式的源仍在 /etc/apt/sources.list.d/debian.sources,需要一并修改 |
| 装中文 locale 包失败 | 启用 non-free,部分语言包在那 |
7. 同系列文章
- AlmaLinux 9:[[posts/almalinux9-yum-repo/index.md]]
- Rocky Linux 9:[[posts/rockylinux9-yum-repo/index.md]]
- CentOS 7:[[posts/centos7-yum-repo/index.md]]
- CentOS Stream 8:[[posts/centosstream8-yum-repo/index.md]]
- RHEL 7/8:[[posts/rhel7-yum-repo/index.md]]
- 离线场景制作本地仓库:[[posts/centos-local-yum-repo/index.md]]
Debian12 APT源配置
https://blog.xeu.asia/posts/debian12-apt-repo/