Linux软件包管理器下载提速需四步:换国内镜像源(如清华、阿里)、启用fastestmirror插件、用aria2替代默认下载器(apt-fast)、调优TCP参数(如启用BBR)。

Linux 软件包管理器本身不原生支持多线程下载,但通过合理配置镜像源、启用加速插件、替换底层下载器或调整网络参数,能显著提升下载速度。关键不在“改仓库”,而在优化下载路径和传输方式。
换国内镜像源(最直接有效)
官方源通常物理距离远、带宽受限,换成国内高校或云服务商镜像可立竿见影:
-
Ubuntu/Debian:编辑
/etc/apt/sources.list,替换成清华、阿里或中科大源,例如:deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse -
CentOS/RHEL/Fedora:备份原 repo 文件后,用阿里云或清华源替换:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo - 改完务必执行
sudo apt update或sudo yum makecache刷新本地索引
启用自动选速插件
让包管理器自己挑最快的镜像,避免手动试错:
-
yum/dnf(RHEL系):确认已安装
yum-plugin-fastestmirror,并确保/etc/yum/pluginconf.d/fastestmirror.conf中enabled=1;maxhostfileage=1让测速缓存每天更新 -
dnf(Fedora):在
/etc/dnf/dnf.conf中添加两行:fastestmirror=truemax_parallel_downloads=10 - 验证是否生效:运行
yum update或dnf update,看到Loading mirror speeds from cached hostfile即表示插件已工作
用 aria2 替代默认下载器(apt 系专属)
apt-fast 不是替代 apt,而是把下载任务交给 aria2 并行处理,效果比单线程高数倍:
- 先装依赖:
sudo apt install aria2 - 配置 aria2:创建
~/.aria2/aria2.conf,至少包含:max-connection-per-server=16split=16min-split-size=1M - 安装 apt-fast:
git clone https://github.com/ilikenwf/apt-fast && cd apt-fast && sudo make install - 之后用法完全一致:
sudo apt-fast update && sudo apt-fast install nginx
调优网络传输层(通用加成)
系统级 TCP 参数优化对所有下载行为都有底层增益:
- 启用 BBR 拥塞控制算法(推荐):
echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.confecho "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.confsudo sysctl -p - 增大接收缓冲区(尤其适合高带宽低延迟环境):
echo "net.core.rmem_max=16777216" | sudo tee -a /etc/sysctl.conf - 验证是否启用:
sysctl net.ipv4.tcp_congestion_control应返回bbr
不复杂但容易忽略——镜像源是基础,插件是杠杆,aria2 是升级,内核参数是底座。四者配合,apt、yum、dnf 的下载体验都能明显不同。


















