1.查看ubuntu的版本,不同的版本对应的不同的镜像源(下面会讲到,先按步骤操作即可)
cat /etc/issue
2.先备份一个,防止更改错误
cp /etc/apt/sources.list /etc/apt/sources.list.backup
3.备份好之后删除原有的sources.list文件
sudo rm -rf sources.list
4.重新创建写入
sudo nano /etc/apt/sources.list
5.这里推荐清华源,先进入清华源,搜索ubuntu,点击问号那里!
6.点进来可以看到可以选择ubuntu不同版本对应的镜像源
7.根据自己选择对应自己ubuntu版本的镜像源,直接复制下来,粘贴到新建的/etc/apt/sources.list下。我这里是22.04的,是下面这样的:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
8.更新,即可完成
sudo apt-get update