一、為什麼要換源
1、提高軟件下載速度
使用默認官方源下載軟件速度通常較慢,而更換國內的鏡像源可以大大提升下載速度。
2、解決軟件更新失敗問題
有些軟件在更新時可能會出現因官方源不可達而更新失敗的情況,更換鏡像源可以解決這類問題。
3、獲得更好的軟件兼容性
國內鏡像站通常會對軟件進行一些本地化的改動,提供更好的兼容性,而在國外鏡像站下載的軟件可能存在一些兼容性問題。
二、如何換源
1、備份當前源配置
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2、編輯源文件
sudo vim /etc/apt/sources.list
一般情況下修改文件中的deb和deb-src為相應的鏡像站地址即可,例如:
# 默認官方源
deb http://archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
# 國內鏡像源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
3、更新源
sudo apt-get update
三、常用的國內鏡像站
1、阿里雲鏡像站
地址:https://developer.aliyun.com/mirror
2、清華大學鏡像站
地址:https://mirrors.tuna.tsinghua.edu.cn/
3、網易163鏡像站
4、中科大鏡像站
地址:https://mirrors.ustc.edu.cn/
5、華為鏡像站
地址:https://mirrors.huaweicloud.com/
四、如何驗證源速度和可用性
1、使用aptitude
sudo aptitude update
aptitude會根據不同源的速度和可用性自動選擇最優的源,可以通過輸出結果看到。
2、使用apt-fast
apt-fast是一個基於apt-get的腳本,加入了多線程下載功能,可以快速下載軟件包。安裝和使用:
sudo add-apt-repository ppa:saiarcot895/myppa
sudo apt-get update
sudo apt-get install apt-fast
sudo apt-fast update
sudo apt-fast upgrade
3、手動測速
可以使用ping、curl等工具手動測試源的速度和可用性。
例如,ping清華大學鏡像站的速度和延遲:
ping mirrors.tuna.tsinghua.edu.cn
五、換源的注意事項
1、更換源時注意備份當前源文件,以便出現問題時恢復原來的配置。
2、最好選擇知名的鏡像站,以免遇到惡意鏡像。
3、不要頻繁更換鏡像站,應該在比較長的時間間隔內使用同一鏡像站。
4、部分軟件不適用於中國境內鏡像站,例如Google Chrome,需要在官方網站下載安裝包。
5、一些特殊的軟件源需要特定的GPG簽名驗證,這些可以在相應鏡像站或軟件開發者的官方安裝文檔中查找。
原創文章,作者:ROMN,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/135018.html