|
|
本帖最后由 达耳闻 于 2026-6-28 09:13 编辑 % R8 \ Z. z) Z2 O( ?* W! E, ^6 G/ @: l
6 U, o S1 H& y r I) h阿里云 https://mirrors.aliyun.com/debian/ 速度快,覆盖广,国内主流选择之一 所有用户: _% [1 P+ n* B" W; y
清华大学 https://mirrors.tuna.tsinghua.edu.cn/debian/ 教育网优化,更新及时,支持IPv6 教育网用户3 |% G& ]2 F" Q+ L
中科大 https://mirrors.ustc.edu.cn/debian/ 历史悠久,连接稳定,尤其适合华中、华东地区 华中、华东用户; K3 `+ E/ b v$ w6 p- g
华为云 https://mirrors.huaweicloud.com/debian/ 企业级服务,稳定性强 企业用户. R, A( K3 O# k: X' g9 e
网易: http://mirrors.163.com/debian/ 老牌镜像站,稳定可靠 所有用户
6 q. p6 }) `) A% n4 h" p腾讯云 https://mirrors.cloud.tencent.com/debian/ 云服务商提供,与云产品集成良好 腾讯云用户1 f' z: h$ v7 B( `2 p8 ^
8 v, h2 U7 E& v* u
9 c/ I# W* A! A" A- @
5 X+ \; W+ M. B更换镜像源方法2 g, C0 V1 X- K2 Q
你有多种方法可以更换镜像源。& O! g+ [8 d. {/ d5 d
+ q/ J, _: R) U9 ?7 \7 _) r/ L方法一:手动编辑源列表文件(推荐,更灵活)
* G2 T) D% R0 m' O' L" d编辑 sources.list 文件:
" v1 Y3 L; N# O3 l$ i+ u: x+ u7 e+ M% ^& o
sudo nano /etc/apt/sources.list" J4 `; ]9 e. t. Z. F& T
注释或删除原有内容,添加以下对应内容(以阿里云和清华大学为例,注意将 trixie 替换为你实际的 Debian 版本代号):" R7 q3 ?9 O$ k2 s7 }- e
8 j4 i) `8 x& G4 a9 F1 J4 M/ ?: d8 }
阿里云镜像源示例(传统格式):' o) l( ]- M& f* {- X
5 T% D) G$ v. Y, K% p1 K: t; ideb https://mirrors.aliyun.com/debian/ trixie main contrib non-free non-free-firmware9 g; z$ x' k. `* l3 D: ?
deb-src https://mirrors.aliyun.com/debian/ trixie main contrib non-free non-free-firmware
9 S' e6 C& i: @: J& w4 m: f' L
7 v; [/ r; Q. n9 B2 q9 ]deb https://mirrors.aliyun.com/debian/ trixie-updates main contrib non-free non-free-firmware
5 ?# f8 U. }( C* O3 U, @deb-src https://mirrors.aliyun.com/debian/ trixie-updates main contrib non-free non-free-firmware
1 I; {- C* y6 M5 F, E3 m4 ~% Y# j; ^7 l" ` i' p
deb https://mirrors.aliyun.com/debian/ trixie-backports main contrib non-free non-free-firmware) H; f4 G3 N9 s }
deb-src https://mirrors.aliyun.com/debian/ trixie-backports main contrib non-free non-free-firmware
+ I2 E: m( x6 u) j0 w) {! l/ D9 R- B2 x& r- k9 |) {$ z& |
# 安全更新源+ \+ x2 j% I1 C) C$ j! C! G
deb https://mirrors.aliyun.com/debian-security trixie-security main contrib non-free non-free-firmware0 V: g+ E0 A( |- ?6 G/ t! G5 P- y
deb-src https://mirrors.aliyun.com/debian-security trixie-security main contrib non-free non-free-firmware/ c% `. j" T* b
清华大学镜像源示例(传统格式):
% U3 F: S1 r, I6 z- I8 c& [7 g& _ x% E& U0 A/ @$ t
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main contrib non-free non-free-firmware- c6 s# R" M/ |, f
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main contrib non-free non-free-firmware
! N! }( W" @) z; X3 z5 a; k- |0 c* P' l! S6 |/ B
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main contrib non-free non-free-firmware$ i, l; ~; P( c. E) V# T
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main contrib non-free non-free-firmware
" d2 J5 S1 n! y" F& m1 i7 ]
. ^1 ~2 W# ?5 t Q) Zdeb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-backports main contrib non-free non-free-firmware v5 x. X7 z9 c6 k. v% O1 z
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-backports main contrib non-free non-free-firmware
3 _- l6 X/ W2 M& S# 安全更新源
# s( z3 Y; A8 N; y5 g( j3 sdeb https://mirrors.tuna.tsinghua.edu.cn/debian-security trixie-security main contrib non-free non-free-firmware" J* X! A' G* [
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security trixie-security main contrib non-free non-free-firmware
l5 ^! R6 f/ A3 ?8 Y, {, ~8 `- U保存并退出编辑器(在 nano 中按 Ctrl+X,然后按 Y 确认,最后按 Enter)。$ W$ L6 L2 {( b: O
0 G6 i. R6 {4 _* ~) A' F
更新软件包列表:6 ?- K% t- F- M5 c1 x
) H& g/ J+ Y0 l# V% w
sudo apt update1 q- U k! {( F- y a! f7 |
特点:最灵活的方法,可以精确控制每个源,适合高级用户和特殊需求。
! @# P! D$ E/ W5 m1 H- a$ h" w& g1 q- m: f0 e. U' Q$ E8 h
方法二:使用 DEB822 格式(新格式,Debian 12 及以上支持)' l1 Z5 e5 L$ y, A
从 Debian 12 开始,系统支持新的 DEB822 格式的源文件,存储在 /etc/apt/sources.list.d/ 目录下,后缀为 .sources。) ^1 x' T2 A) c; [
$ o3 j0 q7 O* [7 u3 S4 F( o
创建或编辑 .sources 文件,例如:
4 G: I s$ h9 k5 f, ?1 F$ C3 g3 |
8 F# X! m" {) o9 j) e2 @. B7 hsudo nano /etc/apt/sources.list.d/debian.sources$ w3 K0 u z; q
添加以下内容(以清华大学源为例,DEB822 格式):" z9 D# a: b w- a( C' i4 E
X- \3 c- V8 p7 _2 @
Types: deb deb-src/ c+ Y5 o. J7 `
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian N. \" f2 p, M) d$ Y2 z
Suites: trixie trixie-updates trixie-backports- r( u/ M. f5 R* k
Components: main contrib non-free non-free-firmware+ g6 ]* S: C2 ^- B8 R( t5 _0 l
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg! L" r' o7 }% q1 G
) ^2 G$ t% A7 n& D$ ^) k0 v
Types: deb deb-src
7 h* y7 B5 ] t& ?" z) H# Z3 kURIs: https://mirrors.tuna.tsinghua.edu.cn/debian-security2 R L! a, T) A/ H& N4 E3 E+ U
Suites: trixie-security
; \( A8 f' C% K" U( OComponents: main contrib non-free non-free-firmware
0 O" _/ i% p* O; w9 HSigned-By: /usr/share/keyrings/debian-archive-keyring.gpg- O( ?5 J7 H' a2 p P# M" ]! F
你也可以选择禁用传统的 sources.list 文件(可选):
2 c) H2 q; Q" R2 Q$ m' D# R
- \+ a! _7 N7 l hsudo mv /etc/apt/sources.list /etc/apt/sources.list.disabled! }7 c: R3 Q# j4 R0 q5 h
更新软件包列表:
( |6 ~. K+ r9 t$ @6 i
) B. y& V) \* \; Jsudo apt update2 H+ N. z) ^. q' j) a; z
特点:新格式更易读和管理,支持多架构和更复杂的源配置,是未来的发展方向。
0 R4 O( O S. D \% b$ C; P8 c+ ^& p% O" W% u
注意事项
/ r* R3 S$ x) p f. t确认 Debian 版本代号:确保配置中使用的版本代号(如 trixie)与你实际运行的 Debian 版本一致。可通过 lsb_release -cs 命令查看。* n% U- |: b w' ~ {: X& ]3 Q! G
# U ^, ~: b5 a5 N# k安全更新源的选择:出于及时性考虑,安全更新(security)建议直接使用 Debian 官方源( https://security.debian.org/debian-security ),因为镜像站同步可能存在延迟。若镜像站提供了安全更新源且你追求速度,也可使用,但需知晓潜在风险。
) I1 i6 m _$ f! a2 R
6 \" v% e/ I& I# B网络问题:如果遇到 Connection reset by peer 等错误,可能与 HTTP Pipelining 特性有关,可以尝试关闭它:. s( r+ }3 Z$ ]5 _9 b: q9 k
; m4 D, w* V, c7 B
echo "Acquire::http: ipeline-Depth \"0\";" | sudo tee /etc/apt/apt.conf.d/99nopipelining
# A* Q) H* S& ?$ d* N2 j6 k, s镜像站同步延迟:镜像站与官方源之间存在同步时间差,通常较短。若更新时找不到某些最新软件包,可稍后再试。
z6 D* G5 u$ L# x/ W
7 d: W* u# c4 S: {代理设置:如果你处于网络受限环境,可能需要配置 HTTP/HTTPS 代理才能访问特定镜像源。
+ f" q2 J" B. ?" B
% q, m# n. I5 x4 @多架构支持:如果你需要安装 i386 等多架构软件包,确保源配置中包含相应组件。
* ]" T, C& R1 ?( }: a
9 p; l2 R2 K+ ` }9 s第三方源:更换系统源后,别忘了也更新第三方软件的源配置(如 Docker、Google Chrome 等),将它们也指向国内镜像。& E2 _( \+ B6 I A ^3 l& \6 b, U
1 @+ G( [4 L5 c( x5 _
测试与验证
3 i; J- R' d1 {- R& d5 v" Q* o8 s更新软件包列表:执行 sudo apt update 后,观察是否有错误信息。若无错误,且列出了新的镜像源地址,则通常表示配置成功。6 X! Z0 N! H! P! K, {
: }- S( N7 K0 W& y( v0 I) ]: c( c o c
速度测试:使用以下命令测试下载速度:$ q v' O; k# r& f# [1 e& U* E
$ o1 i' H: O- s/ T
sudo apt install speedtest-cli1 w3 |7 o; W0 q, `4 M- P! e
speedtest
4 E% h9 F# \2 s! Y# C. T1 M安装测试:尝试安装或更新一个软件包(如 sudo apt install htop),感受下载速度是否有所提升。! i$ Q. y7 Z: g' [3 z q: b
查看源设置:通过 apt policy <package-name> 可查看软件包具体会从哪个源获取。
6 Z( p! K- @2 M* Z1 m( i验证签名:确保所有软件包都能正确验证签名,没有警告信息。% V3 _8 \4 x. o) L) D7 l) T
3 k' f2 x) ^7 u推荐策略:5 j1 C2 |+ d( r( }: C' f
" Z9 e4 w, m4 t: a4 N8 v: ^请注意,镜像源的可用性和速度可能因时间和网络环境而异。如果遇到问题,不妨回退备份或尝试另一个镜像源。定期检查镜像站的状态页面也是好习惯。# {0 I& Z! R( k0 ]
2 z; V+ d$ @( }
|
|