[Linux] Ubuntu 26.04 换阿里云镜像源(最新方法)

适用版本:Ubuntu 26.04 LTS(代号 resolute)

参考:阿里云开发者镜像站 · Ubuntu

默认情况下,Ubuntu 从 archive.ubuntu.com 拉取软件包,国内访问速度缓慢,换成阿里云镜像源之后一般能提升 10x 以上的下载速度。


重要变化:Ubuntu 24.04+ 已弃用 sources.list

从 Ubuntu 24.04 开始,APT 的默认源配置文件从:

bash 复制代码
/etc/apt/sources.list          # 旧格式(Ubuntu 22.04 及更早)

迁移到了 DEB822 格式:

bash 复制代码
/etc/apt/sources.list.d/ubuntu.sources   # 新格式(Ubuntu 24.04+)

Ubuntu 26.04 沿用了这套新格式,因此网上大量基于旧格式的教程(替换 sources.list)在 26.04 上不再适用。


方法一:一键 sed 替换(推荐)

最省事的方式,一条命令完成替换并立即更新:

bash 复制代码
sudo sed -i \
  's|http://archive.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g;
   s|http://security.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g' \
  /etc/apt/sources.list.d/ubuntu.sources

sudo apt update

说明 :-i 直接原地修改,不加 .bak 后缀。如果想保留备份,改为 -i.bak。


方法二:手动编辑配置文件

第一步:备份原始配置

bash 复制代码
sudo cp /etc/apt/sources.list.d/ubuntu.sources \
        /etc/apt/sources.list.d/ubuntu.sources.bak

第二步:编辑配置文件

bash 复制代码
sudo vim /etc/apt/sources.list.d/ubuntu.sources

若提示只读,请确认使用了 sudo。

第三步:替换为以下内容

bash 复制代码
Types: deb
URIs: https://mirrors.aliyun.com/ubuntu
Suites: resolute resolute-updates resolute-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: https://mirrors.aliyun.com/ubuntu
Suites: resolute-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

保存退出(:wq)。

第四步:更新软件包索引

bash 复制代码
sudo apt update

正常情况下能看到从 mirrors.aliyun.com 拉取的 Hit/Get 行,说明换源成功。


方法三:图形界面(新手友好)

系统设置 → 软件和更新 → Ubuntu 软件 → 下载自 ,在下拉列表中选择 mirrors.aliyun.com,确认后系统会自动重新加载软件源。


ARM / PowerPC 架构

本文配置仅适用于 x86_64 架构。如果你使用的是 ARM(如树莓派)、PowerPC 等其他架构,需要改用 ubuntu-ports 镜像,基础 URI 变为:

复制代码
https://mirrors.aliyun.com/ubuntu-ports

验证换源结果

bash 复制代码
# 查看当前配置
cat /etc/apt/sources.list.d/ubuntu.sources

# 测试更新(不实际升级)
sudo apt update

# 安装一个包验证速度
sudo apt install -y curl

如果 apt update 输出中出现 mirrors.aliyun.com,说明换源已生效。


回滚方法

如果新源有问题,直接用备份覆盖还原:

bash 复制代码
sudo cp /etc/apt/sources.list.d/ubuntu.sources.bak \
        /etc/apt/sources.list.d/ubuntu.sources
sudo apt update

常见问题

Q:运行 sed 命令后提示 "No such file or directory"?

A:说明你的系统还在用旧格式。运行 ls /etc/apt/sources.list* 确认文件位置,如果是 sources.list,把上面命令里的路径改为 /etc/apt/sources.list 即可。

24.04 之前旧版本参考 LinuxUbuntu 换源 20.04 阿里源

Q:apt update 报 GPG 错误?

A:不要删除 Signed-By 那行,阿里云镜像签名密钥和官方相同(ubuntu-archive-keyring.gpg),不需要额外导入。

Q:换源后能否直接 apt upgrade 升级所有包?

A:可以,sudo apt upgrade 或 sudo apt full-upgrade,这与换源无关,换源只影响下载速度。

相关推荐
Apipi*12 小时前
30天速通Linux 第六章信号及信号处理
linux·运维·信号处理
AliCloudROS13 小时前
计算巢 X DeepSeek Harness — 云端智能体工作台
人工智能·阿里云
天启HTTP13 小时前
爬虫防封核心原理:IP轮换机制与风控规避逻辑
linux·服务器·网络·爬虫·tcp/ip
广州浮点FLOATLIC16 小时前
许可证服务器迁移后软件打不开:研发 IT 怎样定位连接问题
linux·服务器·数据库
BLUcoding16 小时前
接口服务公网超时排查记录:SecureRandom 阻塞问题分析与解决
java·linux·springboot·aes·securerandom
AIgorithmGEEK16 小时前
[Linux]从手写报头到内核套路:序列化、反序列化与自定义协议全链路
linux·运维·服务器·网络·序列化·反序列化
Nil20816 小时前
leetcode 139单词拆分
linux·运维·服务器
Starry-sky(jing)16 小时前
BUG: unable to handle kernel paging request 完整排查:dmesg 四要素与三路定罪
linux·运维·服务器·内核·排障
mounter62517 小时前
从硬件互连到操作系统变革:CXL 技术演进与 Linux 内核工程挑战
linux·运维·服务器
xh didida18 小时前
Linux -- 基础IO
linux·服务器·开发语言·c++