要修改的文件
/etc/apt/sources.list
操作步骤
1. 备份原文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2. 编辑文件
sudo nano /etc/apt/sources.list
3. 清空文件内容,填入以下内容
先获取Ubuntu版本代号:
lsb_release -cs
然后根据版本填入对应内容(将下面的jammy
替换为版本代号):
# 中科大镜像源(优先级1)
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse# 阿里云镜像源(优先级2)
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse# 网易163镜像源(优先级3)
deb https://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
4. 保存并退出
- 按
Ctrl + X
- 按
Y
确认保存 - 按
Enter
确认文件名
5. 更新软件包列表
sudo apt update
版本代号对照表
- Ubuntu 18.04 →
bionic
- Ubuntu 20.04 →
focal
- Ubuntu 22.04 →
jammy
- Ubuntu 24.04 →
noble
具体操作步骤
1. 先备份原文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2. 编辑sources.list文件
sudo nano /etc/apt/sources.list
3. 清空现有内容,然后粘贴以下内容:
# 中科大镜像源(优先级1)
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse# 阿里云镜像源(优先级2)
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse# 网易163镜像源(优先级3)
deb https://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
4. 保存文件
- 按
Ctrl + X
退出 - 按
Y
确认保存 - 按
Enter
确认文件名
5. 更新软件包列表
sudo apt update
nano编辑器操作提示
在nano编辑器中:
Ctrl + A
- 全选内容Delete
- 删除选中内容(清空文件)Ctrl + Shift + V
或 右键粘贴 - 粘贴内容Ctrl + X
- 退出并保存
就是这样!直接复制粘贴这12行内容到文件里,保存,然后运行 sudo apt update
就完成了。