在 Ubuntu 22.04 上更換為阿里云鏡像源可以加速軟件包的下載和更新,大幅提升系統更新速度。以下是更換阿里云鏡像源的步驟:
1. 備份現有源列表
在更換鏡像源之前,建議先備份當前的源配置文件:
bash
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
此操作將當前源文件備份為 sources.list.bak
,以便在需要時可以恢復。
2. 替換為阿里云鏡像源
編輯 sources.list
文件:
bash
sudo nano /etc/apt/sources.list
刪除或注釋掉原有內容(在每行前添加 #
),然后添加以下阿里云鏡像源內容:
plaintext
# 默認阿里云鏡像源
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-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse# 源碼倉庫(如果需要)
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
說明:
jammy
是 Ubuntu 22.04 的代號。- 如果不需要源碼倉庫,可以省略
deb-src
開頭的行。
保存并退出編輯器(Nano 中按 Ctrl+O
保存,按 Ctrl+X
退出)。
3. 更新軟件包索引
更新軟件包索引以使更換的鏡像源生效:
bash
sudo apt update
4. 驗證新源是否生效
測試是否成功切換到阿里云鏡像源:
bash
sudo apt upgrade
在輸出中,檢查下載的 URL 是否來自 mirrors.aliyun.com
,如:
Get:1 http://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 ...
如果看到 mirrors.aliyun.com
的地址,則說明鏡像源已經生效。
5. 可選:切換到其他國內鏡像源
如果需要其他國內鏡像源,可以選擇以下鏡像源(替換 /etc/apt/sources.list
中的內容即可):
清華大學鏡像源
plaintext
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-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
中國科技大學鏡像源
plaintext
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy 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
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
華為鏡像源
plaintext
deb https://repo.huaweicloud.com/ubuntu/ jammy main restricted universe multiverse
deb https://repo.huaweicloud.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://repo.huaweicloud.com/ubuntu/ jammy-backports main restricted universe multiverse
deb https://repo.huaweicloud.com/ubuntu/ jammy-security main restricted universe multiverse
6. 恢復原始源(如有需要)
如果需要恢復到原始鏡像源,可以使用備份文件:
bash
sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
sudo apt update
通過以上步驟,您可以成功將 Ubuntu 22.04 的鏡像源更換為阿里云或其他國內鏡像源,從而提高系統更新和軟件安裝的速度。