在 Ubuntu 系统中,如果你想把软件源(apt源)切换为阿里云镜像源,并进行更新,可以按照下面的步骤操作:
1. 备份原有源
先备份一下原来的 /etc/apt/sources.list
文件,以防需要恢复:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2. 修改为阿里云源
使用你喜欢的编辑器(比如 vim
、nano
),编辑源文件:
sudo vim /etc/apt/sources.list
然后把原有内容全部清空,换成对应 Ubuntu 版本的阿里云源。
假设你用的是 Ubuntu 24.04(Noble Numbat),可以用下面的阿里云源:
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
如果你是 Ubuntu 22.04(Jammy Jellyfish),则改成:
deb https://mirrors.aliyun.com/ubuntu/ jammy 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
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
如果是别的版本(比如 20.04 Focal),只需要把上面 noble
或 jammy
替换成 focal
。
3. 更新软件包列表
修改好后,执行下面两条命令刷新源并更新:
sudo apt update
sudo apt upgrade -y
4. (可选) 加速 apt
下载
顺便推荐一条命令让 apt
下载变更快:
echo 'Acquire::http { Pipeline-Depth "200"; }; Acquire::https { Pipeline-Depth "200"; }; Acquire::Queue-Mode "access";' | sudo tee /etc/apt/apt.conf.d/99parallel
这样可以让 apt
并行下载,大幅提高速度(特别是国内服务器)。