|
|
本帖最后由 达耳闻 于 2026-6-28 09:13 编辑 ( L" ]% ]0 g7 g/ q* Q; l8 B( B
' a v2 L5 _" c6 k2 A0 ?5 h1 y9 p阿里云 https://mirrors.aliyun.com/debian/ 速度快,覆盖广,国内主流选择之一 所有用户
+ L R2 q0 a1 z/ R清华大学 https://mirrors.tuna.tsinghua.edu.cn/debian/ 教育网优化,更新及时,支持IPv6 教育网用户6 C% o9 N/ x3 _' n
中科大 https://mirrors.ustc.edu.cn/debian/ 历史悠久,连接稳定,尤其适合华中、华东地区 华中、华东用户
& u0 `/ R# Y; f# T. J. j! N华为云 https://mirrors.huaweicloud.com/debian/ 企业级服务,稳定性强 企业用户
# c- M8 [2 i$ g: O( K网易: http://mirrors.163.com/debian/ 老牌镜像站,稳定可靠 所有用户4 d+ J! U; g8 a& X0 l2 N( ]
腾讯云 https://mirrors.cloud.tencent.com/debian/ 云服务商提供,与云产品集成良好 腾讯云用户
# L2 c% f D8 p' c% ]) H
6 _1 a% s o8 m
6 C: G: m, l0 [+ s% I; V
! D- t; L8 w7 ^( d6 ~( N更换镜像源方法1 W! W/ h6 b5 W; i4 c
你有多种方法可以更换镜像源。: G y; R1 D8 I& M; Z/ q3 U
3 O" u9 t. v i' K2 d! }0 H8 f
方法一:手动编辑源列表文件(推荐,更灵活)
1 l5 ` T" k% R6 I% u编辑 sources.list 文件:' H6 @5 S) ?+ V; _/ O9 u' F0 Z
% r/ j- s% O! n7 i# z1 |8 F, b2 w
sudo nano /etc/apt/sources.list/ E ]% U5 J3 Z, ]4 R$ }
注释或删除原有内容,添加以下对应内容(以阿里云和清华大学为例,注意将 trixie 替换为你实际的 Debian 版本代号):5 E0 u% }5 d0 _# v, g4 p/ @
6 D! e- O3 b6 e- i1 s! ]* L
阿里云镜像源示例(传统格式):/ U2 y0 \4 r) H: k% H9 u1 D
/ a' W$ \+ q+ W; T- d2 \+ s$ g% b' L; ideb https://mirrors.aliyun.com/debian/ trixie main contrib non-free non-free-firmware
4 J: x1 Y( i; g5 h; Ddeb-src https://mirrors.aliyun.com/debian/ trixie main contrib non-free non-free-firmware
) k& `: a* G/ b
( q) O' b! B$ d& s) Ydeb https://mirrors.aliyun.com/debian/ trixie-updates main contrib non-free non-free-firmware
! ?, `1 X# Z* N ^4 L/ ^5 B; {deb-src https://mirrors.aliyun.com/debian/ trixie-updates main contrib non-free non-free-firmware. b- L! ?9 T5 h5 [' j# F
. D! d; u) j G# G% }: |deb https://mirrors.aliyun.com/debian/ trixie-backports main contrib non-free non-free-firmware
8 x' o5 D3 C( H$ x) adeb-src https://mirrors.aliyun.com/debian/ trixie-backports main contrib non-free non-free-firmware
2 D R" k8 P, F6 o$ I- B/ W3 d( \7 O% H
# 安全更新源
4 c8 }) g8 F" v- ?3 r3 Odeb https://mirrors.aliyun.com/debian-security trixie-security main contrib non-free non-free-firmware$ h# D# m7 o4 W) C
deb-src https://mirrors.aliyun.com/debian-security trixie-security main contrib non-free non-free-firmware$ j+ Z* E9 e8 C' B2 ]
清华大学镜像源示例(传统格式):
- y3 y) t5 J4 j/ \5 n" @7 r
) F0 x" W$ Q4 X/ ?3 rdeb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main contrib non-free non-free-firmware
B4 L/ A$ |+ U: k& qdeb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main contrib non-free non-free-firmware
* L6 C- U( Q8 q# g; e2 n2 N% b" D6 \" \6 P" {6 W, g7 d" ]
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main contrib non-free non-free-firmware
; ]' D m1 J" ~9 a& Q) sdeb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main contrib non-free non-free-firmware/ o. l; O. {4 c8 I+ T+ K) \
$ X/ G8 g5 F% x* ?
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-backports main contrib non-free non-free-firmware
! W8 w+ c5 B6 t4 r- Q3 cdeb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-backports main contrib non-free non-free-firmware
9 @7 ?2 N" D( u; U. P5 l, q& Q- Z& a! B# 安全更新源% A' x" a, R- p$ E2 p
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security trixie-security main contrib non-free non-free-firmware
& a! v- |" R- b4 ~deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security trixie-security main contrib non-free non-free-firmware6 S: N( c t2 h7 E- \. I
保存并退出编辑器(在 nano 中按 Ctrl+X,然后按 Y 确认,最后按 Enter)。
# [; m4 Q1 Z) n" y& H2 r, v$ r$ k! \5 U( p( L) N/ S
更新软件包列表:
8 D9 q. a, {2 \4 v& F2 v' `9 p, ~
% k) |. ^% d% I2 \0 X* ?; ]: ssudo apt update
! |) h1 `0 U. T1 s9 E& L. ^特点:最灵活的方法,可以精确控制每个源,适合高级用户和特殊需求。0 f) `# |) _0 v' X
7 e/ k+ G+ `% T1 q! R& Q1 \方法二:使用 DEB822 格式(新格式,Debian 12 及以上支持)
- v- C3 f/ Q0 b) S) R- p从 Debian 12 开始,系统支持新的 DEB822 格式的源文件,存储在 /etc/apt/sources.list.d/ 目录下,后缀为 .sources。9 x7 [3 b2 S3 T
4 T. P) A! A0 l$ [' d9 y创建或编辑 .sources 文件,例如:( D9 X& I, F. A" }
) ], ]9 g3 b6 X9 ]/ w
sudo nano /etc/apt/sources.list.d/debian.sources8 r; c. O3 K2 h% O9 r0 l
添加以下内容(以清华大学源为例,DEB822 格式):' p# ]- Y. r6 m1 a9 j
3 g1 V/ y. ~2 V
Types: deb deb-src, f% e. z& |. Z: L) P
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian& S" O5 N: Q2 x$ v& s/ p
Suites: trixie trixie-updates trixie-backports
- _0 N) O4 {; PComponents: main contrib non-free non-free-firmware: w4 Q& G, ^# z8 Y; ]: S
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
6 a% k$ V6 ?) q0 \) R Y- e
0 z% o& w& ^* K ~/ E# nTypes: deb deb-src7 ` M6 S5 Q: n9 c% _, K2 d
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian-security
% O) M) j, Z( Z& Y6 `) @9 fSuites: trixie-security
' Y- q9 p4 ~1 k3 E* BComponents: main contrib non-free non-free-firmware
! U: _- e% d5 l- d. rSigned-By: /usr/share/keyrings/debian-archive-keyring.gpg7 E/ q# g* U& M x; M7 D* {0 R
你也可以选择禁用传统的 sources.list 文件(可选):; k3 g; c- q: o6 d+ n9 \, k% ~* B
, s2 i l( S4 ?: b% z& f; L
sudo mv /etc/apt/sources.list /etc/apt/sources.list.disabled
8 p9 ^8 k W7 ]) H( s! A7 T6 |* Z更新软件包列表:
9 m, }, n( O5 o* U4 t( r3 v2 I" O+ }9 K" x
sudo apt update" u( V7 Z" I2 X5 w1 d8 @+ h
特点:新格式更易读和管理,支持多架构和更复杂的源配置,是未来的发展方向。
2 K5 x/ f9 j: J- L" n
5 D! @ e- }( n注意事项
6 g1 b0 @; q) S( b; n+ [确认 Debian 版本代号:确保配置中使用的版本代号(如 trixie)与你实际运行的 Debian 版本一致。可通过 lsb_release -cs 命令查看。
( q; q$ X# Z5 h) f3 S1 w/ V/ `6 S+ p. s
安全更新源的选择:出于及时性考虑,安全更新(security)建议直接使用 Debian 官方源( https://security.debian.org/debian-security ),因为镜像站同步可能存在延迟。若镜像站提供了安全更新源且你追求速度,也可使用,但需知晓潜在风险。
. R$ ~6 t& ?' X0 t1 y+ a3 }
: [$ ?) ~9 c, n9 F网络问题:如果遇到 Connection reset by peer 等错误,可能与 HTTP Pipelining 特性有关,可以尝试关闭它:
- z7 h) ^& E; N7 k( j7 a3 L
6 r0 g- g) }, g4 ?echo "Acquire::http: ipeline-Depth \"0\";" | sudo tee /etc/apt/apt.conf.d/99nopipelining
6 b/ |, K& [7 ?, o9 U& u镜像站同步延迟:镜像站与官方源之间存在同步时间差,通常较短。若更新时找不到某些最新软件包,可稍后再试。
4 `' b! d( w: X4 i
& A1 j V. Y; K5 D2 E p7 \9 ?5 d代理设置:如果你处于网络受限环境,可能需要配置 HTTP/HTTPS 代理才能访问特定镜像源。& C: M9 a- V) o2 }% t
4 z7 f' E( U) i; A2 F7 K2 m
多架构支持:如果你需要安装 i386 等多架构软件包,确保源配置中包含相应组件。; T9 z$ W, y; k7 }1 q
f$ R! ~9 k O3 a: u. k4 z
第三方源:更换系统源后,别忘了也更新第三方软件的源配置(如 Docker、Google Chrome 等),将它们也指向国内镜像。
4 a7 d3 [5 X; O8 x$ a
* b6 o3 C) ?% W8 Z0 I( q3 |测试与验证7 C9 w/ D9 D8 k
更新软件包列表:执行 sudo apt update 后,观察是否有错误信息。若无错误,且列出了新的镜像源地址,则通常表示配置成功。
4 j9 D% b r: p4 O* Q
, p5 {$ J2 |2 d/ ~8 J# j速度测试:使用以下命令测试下载速度:- \3 Y; R$ C; {+ m- [
9 J$ i0 d n, R1 {3 T5 Msudo apt install speedtest-cli
2 _" P0 u6 D3 |- ^7 kspeedtest2 S/ [& w+ q- m7 h# I" _
安装测试:尝试安装或更新一个软件包(如 sudo apt install htop),感受下载速度是否有所提升。
" K2 Q2 p" F1 ~% S/ W/ W0 K查看源设置:通过 apt policy <package-name> 可查看软件包具体会从哪个源获取。
$ P+ @5 w! M; o/ K8 W验证签名:确保所有软件包都能正确验证签名,没有警告信息。
2 N: M2 N" b1 d3 a7 U: B( i( N3 b% t- c! e$ t
推荐策略:3 M& }% X l! D8 Q, j1 R
3 `, O" A1 d6 G4 x' j2 ]. x$ j请注意,镜像源的可用性和速度可能因时间和网络环境而异。如果遇到问题,不妨回退备份或尝试另一个镜像源。定期检查镜像站的状态页面也是好习惯。5 C9 g! Y8 r5 j
$ Y) l# i% \& K0 V |
|