官方 apt 源在國內的連線速度往往不盡理想,把來源換成阿里雲鏡像站是常見的優化手段。以下內容對應 Ubuntu 14.04.1(代號 trusty),可直接覆寫 /etc/apt/sources.list。
deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
每行開頭的 deb 表示這是可下載的其二進位套件來源,deb-src 則對應原始碼套件,需要自行編譯時才用得到,日常運維若不需要可以整段註解掉。
中間的 trusty 是發行版代號,後面接著四個元件:main 為官方主線軟體、restricted 為受限授權軟體、universe 為社群維護、multiverse 為非自由軟體。security 是安全更新、updates 是常規更新、proposed 是尚未正式上架的候選版本、backports 則是回移的新版套件。
sudo apt-get update sudo apt-get upgrade
更新索引時若大量 Package 檔都從 mirrors.aliyun.com 下載,就代表切換成功。提醒一點:代號必須與自己的系統版本相符,若實際是 16.04(xenial)或 18.04(bionic),把 trusty 一併替換即可,否則會出現依賴衝突。