Debian 13 换源

最后更新于:

Debian 13 换源指南

1 文档说明

本文档将详细介绍如何为 Debian 13 操作系统更换软件源,包括官方源与国内常用镜像源的配置方法,适用于服务器与桌面版用户。更换软件源可显著提升软件下载速度,解决因网络问题导致的包管理工具(apt)操作失败问题。

适用环境

  • 操作系统:Debian 13

  • 权限要求:需要 root 或 sudo 权限

  • 网络要求:确保服务器 / 电脑已连接互联网

2 换源前准备工作

2.1 备份原有源文件

在修改软件源配置前,建议先备份系统默认的源列表文件,以便后续出现问题时可恢复。

执行以下命令备份原有源文件:

1# 备份默认源列表(推荐)
2
3sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
4
5# 若存在 sources.list.d 目录下的额外源,也建议备份
6
7sudo cp -r /etc/apt/sources.list.d /etc/apt/sources.list.d.bak

2.2 查看系统版本

确认当前系统为 Debian 13 ,避免因版本不匹配导致源配置错误。

执行以下命令查看系统版本:

1# 方法1:查看 /etc/os-release 文件
2
3cat /etc/os-release
4
5# 方法2:查看系统版本信息
6
7lsb_release -a

正确输出示例

1PRETTY_NAME="Debian GNU/Linux 13 "
2
3NAME="Debian GNU/Linux"
4
5VERSION_ID="13"
6
7VERSION="13 "
8
9VERSION_CODENAME=trixie

3 软件源配置详解

Debian 软件源列表(/etc/apt/sources.list)的每条记录格式为:

1deb [选项] 源地址 发行版代号 软件包分类1 软件包分类2 ...
  • deb:表示二进制软件包源(常用);deb-src 表示源代码包源(可选)

  • 发行版代号:Debian 13 固定为 trixie

  • 软件包分类:默认包含 main(官方支持)、contrib(依赖非自由软件)、non-free(非自由软件)

3.1 方案 1:使用 Debian 官方源(全球通用)

官方源稳定性最高,适合海外服务器或网络条件较好的用户。

编辑源列表文件:

1sudo nano /etc/apt/sources.list

将文件内容替换为以下官方源(保留 deb-src 可按需下载源代码):

 1# Debian 13  官方源 - 主源
 2
 3deb http://deb.debian.org/debian/ trixie main contrib non-free non-free-firmware
 4
 5deb-src http://deb.debian.org/debian/ trixie main contrib non-free non-free-firmware
 6
 7# 安全更新源(重要,需保留)
 8
 9deb http://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
10
11deb-src http://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
12
13# 稳定更新源(系统bug修复,可选)
14
15deb http://deb.debian.org/debian/ trixie-updates main contrib non-free non-free-firmware
16
17deb-src http://deb.debian.org/debian/ trixie-updates main contrib non-free non-free-firmware

3.2 方案 2:使用国内镜像源(推荐国内用户)

国内镜像源由高校或企业提供,下载速度远快于官方源,常见选择包括阿里云、清华大学、中科大等。

3.2.1 阿里云镜像源(推荐)

编辑源列表文件:

1sudo nano /etc/apt/sources.list

替换为以下内容:

 1# 阿里云 Debian 13  镜像源
 2
 3deb http://mirrors.aliyun.com/debian/ trixie main contrib non-free non-free-firmware
 4
 5deb-src http://mirrors.aliyun.com/debian/ trixie main contrib non-free non-free-firmware
 6
 7# 安全更新源
 8
 9deb http://mirrors.aliyun.com/debian-security/ trixie-security main contrib non-free non-free-firmware
10
11deb-src http://mirrors.aliyun.com/debian-security/ trixie-security main contrib non-free non-free-firmware
12
13# 稳定更新源
14
15deb http://mirrors.aliyun.com/debian/ trixie-updates main contrib non-free non-free-firmware
16
17deb-src http://mirrors.aliyun.com/debian/ trixie-updates main contrib non-free non-free-firmware

3.2.2 清华大学镜像源(备选)

若阿里云源速度不佳,可替换为清华大学镜像源:

 1# 清华大学 Debian 13  镜像源
 2
 3deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main contrib non-free non-free-firmware
 4
 5deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main contrib non-free non-free-firmware
 6
 7# 安全更新源
 8
 9deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ trixie-security main contrib non-free non-free-firmware
10
11deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ trixie-security main contrib non-free non-free-firmware
12
13# 稳定更新源
14
15deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main contrib non-free non-free-firmware
16
17deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main contrib non-free non-free-firmware

4 应用新源并验证

4.1 更新源缓存

修改源列表后,需执行以下命令更新 apt 缓存,使新源生效:

1sudo apt update

注意:若执行过程中出现 GPG 密钥错误,无需担心,后续步骤会自动修复;若出现 无法连接,请检查源地址是否正确、网络是否通畅。

4.2 升级系统软件(可选)

更新缓存后,可按需升级系统中已安装的软件包,确保与新源同步:

1sudo apt upgrade -y
  • -y:自动确认所有升级操作,无需手动输入 y

5 常见问题排查

5.1 “GPG 密钥无法验证” 错误

现象:执行 sudo apt update 时提示 The following signatures couldn’t be verified because the public key is not available

解决方法:导入缺失的 GPG 密钥(以阿里云源为例):

1# 下载并导入阿里云源的 GPG 密钥
2
3wget http://mirrors.aliyun.com/debian-security/project-unsigned/ -O - | sudo apt-key add -

或通用方法:

1# 安装缺失的密钥环包
2
3sudo apt install -y debian-keyring debian-archive-keyring

5.2 “无法连接到源服务器” 错误

可能原因

  • 源地址错误(如将 trixie 写成 bullseyebookworm);

  • 网络问题(防火墙拦截、DNS 解析失败);

  • 镜像源暂时下线。

解决方法

  • 核对源列表中的发行版代号是否为 trixie

  • 测试源地址连通性:ping ``mirrors.aliyun.com(若不通,检查网络设置);

  • 更换其他镜像源(如从阿里云换为清华大学源)。

5.3 恢复默认源

若更换源后出现严重问题,可通过备份文件恢复默认源:

 1# 恢复备份的源列表
 2
 3sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
 4
 5# 恢复 sources.list.d 目录(若之前备份过)
 6
 7sudo cp -r /etc/apt/sources.list.d.bak /etc/apt/sources.list.d
 8
 9# 重新更新缓存
10
11sudo apt update

6 补充说明

  • non-free-firmware分类:Debian 13 新增该分类,用于存放硬件固件(如无线网卡、显卡固件),建议保留以避免硬件驱动问题。
  • 源的优先级:若 sources.listsources.list.d 目录下有多个源,apt 会按文件顺序和源的优先级选择,建议保持源列表简洁,避免重复配置。
  • 定期更新源缓存:建议每周执行 sudo apt update 一次,确保获取最新的软件包信息。

7 Linux 重启命令

1# linux重启命令
2init6
推荐使用微信支付
微信支付二维码
推荐使用支付宝
支付宝二维码
最新文章

文档导航

此分类暂无内容