在 Ubuntu 中,修改软件源可以加速软件更新和安装速度,特别是对于中国用户,可以更换为大陆镜像源(如阿里云、清华、网易等)。以下是详细的修改方法:
1. 备份原有软件源
在修改前,建议先备份原来的 sources.list 文件,以防出错后恢复:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2. 编辑 sources.list 文件
使用 nano 或 vim 编辑 Ubuntu 的软件源列表:
sudo nano /etc/apt/sources.list
或者:
sudo vim /etc/apt/sources.list
清空原内容,然后根据你的 Ubuntu 版本,选择适合的软件源。
3. 常见的大陆软件源
以下是常见的大陆镜像源,选择一个合适的替换 sources.list 中的内容:
(1)阿里云源
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
(2)清华大学源
deb 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 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
(3)网易源
deb http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
说明:
Ubuntu 22.04 对应代号 jammy
Ubuntu 20.04 对应代号 focal
Ubuntu 18.04 对应代号 bionic
请根据你的系统版本,替换 jammy 为对应的代号。
4. 更新软件源
修改完成后,按 Ctrl + X 退出,按 Y 保存,然后执行:
sudo apt update && sudo apt upgrade -y
5. 还原原来的软件源(如果出错)
如果新源导致问题,可以恢复备份:
sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
sudo apt update
通过以上的方法,这样你的 Ubuntu 就能使用大陆更快的软件源进行更新了!