更換Ubuntu源為國內源的操作記錄


 

我們都知道,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 更新軟件 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM