Ubuntu APT源配置
簡介
目前,Linux系統已經逐漸被很多開發者所接受和喜好,尤其是Ubuntu系統更是將Linux的桌面系統做的相當完善,本文主要介紹修改Ubuntu默認軟件安裝工具apt軟件源,這是考慮到Ubuntu的默認源在國外速度較慢,本文修改爲阿里源。
具體步驟
備份配置文件
以防萬一,需要將原來的apt源配置文件備份,使用下面的命令即可。(apt軟件源配置文件爲/etc/apt/sources.list
,記錄所有軟件包的倉庫,同類型的還有同級目錄下sources.list.d/
的以list
爲後綴的文本文件。)
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
查看系統代號
很多時候網上查閱apt源配置教程,得到的結果不太一樣,這是因爲Ubuntu每個版本的系統代號都不一致,通過命令lsb_release -c
查看。例如,Ubuntu18.04的代號如下。
修改配置文件
將第一步中的配置文件修改如下,更改爲阿里源,注意格式。
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
上述bionic爲Ubuntu18的系統代號,其他版本需要修改成對應代號,如圖。
上述的格式如下。
deb http://site.example.com/ubuntu distribution component1 component2 component3
deb-src http://site.example.com/ubuntu distribution component1 component2 component3
後面的幾個參數是對軟件的分支和類別,這裏填上圖四個main
, restricted
,universe
,multiverse
即可。
更新軟件列表
執行sudo apt-get update
,此時可能會報錯GPG error: http://dl.google.com/linux/chrome/deb stable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 78BD65473CB3BD13
,這是公鑰的問題,執行sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 報錯說明的公鑰
即可添加,此時再次執行sudo apt-get update
即可更新軟件列表。
更新軟件包
執行命令sudo apt-get upgrade
進行已安裝的軟件更新,注意該命令是更新所有已安裝軟件,時間較長,謹慎使用。
補充說明
本文主要介紹如何修改Ubuntu18.04的默認apt軟件源爲阿里源,加速軟件包的安裝。