运行lsb_release -sc命令可精准获取当前ubuntu版本代号(如noble或jammy),填错代号是apt update报404或“release file缺失”的最常见原因,务必以该命令输出为准,不可凭年份或旧教程猜测。

怎么确认当前 Ubuntu 版本代号(Codename)
填错代号是 apt update 报 404 或 “The repository does not have a Release file” 的最常见原因。别猜、别查年份、别信网上旧教程写的 bionic 或 focal —— 2026 年主流是 jammy(22.04 LTS)和 noble(24.04 LTS)。
直接运行:lsb_release -sc
它只输出一行,比如 jammy,这就是你要用的代号。
不确定时,打开浏览器访问:https://mirrors.aliyun.com/ubuntu/dists/jammy/(把 jammy 换成你跑出的代号),看页面能否打开。打不开就说明代号错了。
为什么不能只替换 archive.ubuntu.com 为 mirrors.aliyun.com
阿里源、清华源等镜像站的目录结构和官方不同,security 和 updates 子路径不是简单拼接出来的。只改域名会导致:
• apt update 卡在 “Failed to fetch”
• 安全更新(-security)失效,系统漏补丁
• g++、build-essential 等包装不上(因为依赖 deb-src 行)
必须使用完整配置块,包含四类源:
• 主仓库(main restricted universe multiverse)
• 安全更新(-security)
• 常规更新(-updates)
• 回滚支持(-backports)
每类都要配 deb 和 deb-src 行。
编辑 /etc/apt/sources.list 的实操要点
先备份:sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
再用 nano 编辑:sudo nano /etc/apt/sources.list
Linux系统管理专家,覆盖12大模块:用户权限、SSH、存储、网络、systemd、防火墙、日志监控、备份恢复、TLS证书、Ansible、容器、IaC。提供配置、验证、加固、监控、备份、自动化、故障排查、回滚闭环。关键词:useradd、sudo、sshd_config、chmod、SEL...
清空原内容,粘贴对应代号的完整配置(以 jammy 为例):
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse<br>deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse<br>deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse<br>deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse<br>deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse<br>deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse<br>deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse<br>deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
注意:
• 不要用 https 协议(阿里源目前不支持 HTTPS,会报连接失败)
• 别加 -proposed 源(不稳定,普通用户不需要)
• deb-src 行建议保留,否则 apt-get source 或调试编译会失败
执行 apt update 后仍报错怎么办
常见错误现象:
• 出现大量 Ign:1 ... 或 404 Not Found
• 提示 “The repository does not have a Release file”
优先检查这三项:
• 运行 lsb_release -sc 核对代号是否写错(比如把 noble 写成 24.04)
• 检查是否混用了 https(应全用 http)
• 确认是否漏掉了 -security 或 -updates 行(缺一行就可能让整个 update 失败)
修复后,执行:sudo apt clean && sudo apt updateclean 能清掉缓存里残留的旧 Release 文件,避免干扰。
最后提醒:Ubuntu 24.04(noble)起默认使用 DEB822 格式的 /etc/apt/sources.list.d/ubuntu.sources,若你系统里没有 sources.list 文件,得改那个,格式完全不同——这点容易被忽略。










