1. 详细步骤
1.1 查看源文件位置(可跳过)
# 传统格式
more /etc/apt/sources.list
# DEB822 格式
more /etc/apt/sources.list.d/ubuntu.sources
注:后续步骤都以传统格式的 /etc/apt/sources.list 为例
1.2 备份源文件
sudo mv /etc/apt/sources.list /etc/apt/sources_back.list
1.3 配置镜像源
# 配置清华源(如果 vim 保存不成功,切到 root 用户再试试)
sudo vim /etc/apt/sources.list
# 内容如下(以 Ubuntu 22.04 LTS(jammy) 版为例,其他版本请查阅 https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/)
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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 http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
1.4 验证
sudo apt update
sudo apt install xxx
2. 参考资料
2.1 清华大学开源软件镜像站
ubuntu
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/