Ubuntu 22.04.5 LTS 镜像源更新

在下载镜像时无法访问下载镜像,查询资料后,发现需要更新为国内镜像源。在此记录详细步骤以便后续参考。

1. 查看当前 Ubuntu 版本

在更新镜像源之前,首先需要确认当前系统的 Ubuntu 版本。( 后面会用到,这里是 Codename: jammy )

lsb_release -a

root@DESKTOP:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.5 LTS
Release:	22.04
Codename:	jammy

2. 镜像源修改

2.1 先备份一下镜像源文件

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

2.2 整理镜像源链接

注意:这里每个链接的 jammy 是 Ubuntu 22.04.5 LTS 对应的代码号
不同版本的代码号不同,自行使用上面 lsb_release -a 命令查阅后更换链接中的代码号

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiver

2.3 编辑镜像源

# 打开vim
sudo vim /etc/apt/sources.list

# 清空数据
按左上角esc键后,再输入 dG (该命令谨慎用于其他文件)

# 按 i 进入编辑模式,把上面整理的镜像链接复制进来

# 输入 :wq 保存退出 (注意:)

3. DNS编辑

添加镜像源后可能还无法更新镜像,此时可能是dns配置有问题

3.1 备份配置

sudo cp /etc/resolv.conf /etc/resolv.conf.bak

3.2 编辑配置

# 打开vim
sudo vim  cp /etc/resolv.conf

# 按 i 进入编辑模式,把下面两行阿里云配置复制到最下面
nameserver 223.5.5.5  
nameserver 223.6.6.6

# 输入 :wq 保存退出 (注意:)

3.2 更新配置、配置永久保存

此处参考 https://www.laozuo.org/25628.html

# 更新配置
sudo resolvconf -u

# 配置永久保存
systemctl restart systemd-resolved
systemctl enable systemd-resolved
ln -s /run/systemd/resolve/resolv.conf /etc/

4. 更新镜像包

更新成功即可去下载镜像了

sudo apt-get update
sudo apt-get upgrade
posted @ 2025-02-21 15:17  mjsly  阅读(1500)  评论(0)    收藏  举报