对于使用Ubuntu22.04或Ubuntu24.04的用户来说,配置一个快速稳定的apt源是提升软件安装体验的关键步骤。默认的官方源在国外,国内下载速度往往很慢,甚至出现连接失败。本文将手把手教你如何配置国内镜像源,让配置apt源变得简单高效。
在修改任何系统配置文件前,养成备份的好习惯。执行以下命令备份sources.list:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
国内有许多优秀的Ubuntu镜像源,例如阿里云、清华大学、中科大等。下面以阿里云源为例(适用于Ubuntu22.04软件源和Ubuntu24.04软件源)。
使用文本编辑器(如nano或vim)打开源列表文件:
sudo nano /etc/apt/sources.list
删除原有内容,替换为以下阿里云镜像配置(注意根据版本选择对应代号:22.04为jammy,24.04为noble):
# Ubuntu 22.04 (jammy) 阿里云源deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse# Ubuntu 24.04 (noble) 阿里云源(请根据实际系统版本选用)# deb http://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse# deb http://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse# deb http://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse# deb http://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse# deb http://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
保存并退出(nano按Ctrl+O,Ctrl+X;vim按Esc,输入:wq)。
运行以下命令使新配置生效:
sudo apt update
看到“正在读取软件包列表... 完成”即表示sources.list配置成功。如果遇到GPG错误,可能需要导入缺失的密钥,但国内镜像通常已处理好。
尝试安装一个小软件测试速度,例如:
sudo apt install htop
如果下载速度明显提升,说明apt国内镜像配置成功。
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 缺失密钥解决。—— 让你的Ubuntu飞起来!
本文由主机测评网于2026-03-16发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://vpshk.cn/20260331735.html