我們都知道,Ubuntu的官方源對於國內使用者來說是比較慢的,可以將它的源換成國內的源(比如阿里源),這樣用起來就很快了。下面記錄下更換操作:
首先了解下/etc/apt/sources.list檔案 檔案/etc/apt/sources.list是一個普通可編輯的文字檔案,儲存了ubuntu軟體更新的源伺服器的地址。 和sources.list功能一樣的是/etc/apt/sources.list.d/*.list(*代表一個檔名,只能由字母、數字、下劃線、英文句號組成), 該資料夾下的檔案是第三方軟體的源,可以分別存放不同的第三源地址,只需“副檔名”為list即可。 sources.list.d目錄下的*.list檔案為在單獨檔案中寫入源的地址提供了一種方式,通常用來安裝第三方的軟體。 如下是ubuntu官方sources.list檔案內容: deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse 以上內容的具體含義如下: 1)每一行的開頭是deb或者deb-src,分別表示直接通過.deb檔案進行安裝和通過原始檔的方式進行安裝。 2)deb或者deb-src欄位之後,是一段URL,之後是五個用空格隔開的字串,分別對應相應的目錄結構。 在瀏覽器中輸入http://archive.ubuntu.com/ubuntu/,並進入dists目錄,可以發現有5個目錄和前述sources.list檔案中的第三列欄位相對應。 任選其中一個目錄進入,可以看到和sources.list後四列相對應的目錄結構 以上官方的ubuntu源在國內使用,通常都會很慢,以至於在使用過程中報錯。 ----------------下面是我線上上使用過的一個ubuntu的源--------------------- root@ubuntutest03-KVM:~# cat /etc/apt/sources.list|grep -v "^#"|grep -v "^$" deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted deb http://cn.archive.ubuntu.com/ubuntu/ xenial universe deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe deb http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu xenial-security main restricted deb http://security.ubuntu.com/ubuntu xenial-security universe deb http://security.ubuntu.com/ubuntu xenial-security multiverse --------------下面是替換成阿里源的內容------------- root@ubuntutest03-KVM:~# cat /etc/apt/sources.list deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse ##測試版源 deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse # 原始碼 deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse ##測試版源 deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse # Canonical 合作伙伴和附加 deb http://archive.canonical.com/ubuntu/ xenial partner deb http://extras.ubuntu.com/ubuntu/ xenial main root@ubuntutest03-KVM:~# apt-get update 更新源 root@ubuntutest03-KVM:~# apt-get upgrade 更新軟體 -------------更換成其他開放的ubuntu源,做法和上面同理---------------- 再比如下面更換成網易源(開啟檔案中的url。進入dists目錄下就能看到xenial等對應的目錄結構了) root@ubuntutest03-KVM:~# cat /etc/apt/sources.list deb http://mirrors.163.com/ubuntu/ xenial main restricted deb http://mirrors.163.com/ubuntu/ xenial-updates main restricted deb http://mirrors.163.com/ubuntu/ xenial universe deb http://mirrors.163.com/ubuntu/ xenial-updates universe deb http://mirrors.163.com/ubuntu/ xenial multiverse deb http://mirrors.163.com/ubuntu/ xenial-updates multiverse deb http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu xenial-security main restricted deb http://security.ubuntu.com/ubuntu xenial-security universe deb http://security.ubuntu.com/ubuntu xenial-security multiverse root@ubuntutest03-KVM:~# apt-get update 更新源 root@ubuntutest03-KVM:~# apt-get upgrade 更新軟體