475 字
2 分钟
Debian12 APT源配置

Debian 12 (bookworm) 默认的 deb.debian.org 走海外节点,国内访问速度感人。把 /etc/apt/sources.list 替换为阿里云或腾讯云镜像即可。

1. 备份原配置#

Terminal window
$ mv /etc/apt/sources.list /etc/apt/sources.list.bak

Debian 12 部分场景下源配置改放到 /etc/apt/sources.list.d/debian.sources(DEB822 新格式),如果 sources.list 是空的,需要去 sources.list.d/ 下找文件改。

2. 阿里云源#

Terminal window
$ cat > /etc/apt/sources.list <<EOF
deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-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 contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
EOF

3. 腾讯云源(备选)#

Terminal window
$ cat > /etc/apt/sources.list <<EOF
deb https://mirrors.cloud.tencent.com/debian/ bookworm main non-free non-free-firmware contrib
deb-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 main
deb-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 contrib
deb-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 contrib
deb-src https://mirrors.cloud.tencent.com/debian/ bookworm-backports main non-free non-free-firmware contrib
EOF

阿里云和腾讯云源二选一,不要同时启用,否则 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. 更新源#

Terminal window
$ apt update
$ apt upgrade -y

6. 常见问题#

现象处理
apt updateNO_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/
作者
Xeu
发布于
2025-05-05
许可协议
CC BY-NC-SA 4.0