Ubuntu 修改成國內軟件源(apt-get)

背景

 有時使用apt-get安裝依賴庫或軟件時,看到15KB~40KB的速度下載,真的是恨鐵不成剛,爲什麼不能快一些呢;明明電腦下載時都有1M~3M的,感到無奈,一直在等待安裝。如果排除是電腦本身網絡速度慢問題,那很有可能是安裝依賴庫或軟件是外網的,需要從外網那裏獲取;這樣自然就很慢啦。

 

修改成國內軟件源(apt-get)

1. 備份原始文件

 2.修改 sources.list 文件的權限

3. 修改文件並添加國內源

 4.註釋原文件內的源並添加如下地址 


1. 備份原始文件

sudo cp /etc/apt/sources.list /etc/apt/sources.list2

 2.修改 sources.list 文件的權限

sudo chmod 777 /etc/apt/sources.list 

3. 修改文件並添加國內源

vi /etc/apt/sources.list

不喜歡用 vi 編譯器的可以使用 gedit 

gedit /etc/apt/sources.list

 

 4.註釋原文件內的源並添加如下地址 

不同的系統版本對應的軟件源也是不一樣的,之前被坑了;以爲ubuntu系統下,使用的軟件源應該都一樣的,後來發現替換源後,部分軟件無法安裝,經過調查發現不同的系統版本對應的不同的軟件源;

比如同一個品牌的軟件源(網易163),也會區分是ubuntu18、ubuntu16還是ubuntu14系統的。

#阿里雲 (推薦)Ubuntu18

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

 

#網易163(這個速度比較快)Ubuntu18

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
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

 

#阿里雲 (推薦)Ubuntu16

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-proposed main restricted universe multiverse  
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports 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-proposed main restricted universe multiverse  
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

#網易163(這個速度比較快)Ubuntu16

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-proposed main restricted universe multiverse  
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports 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-proposed main restricted universe multiverse  
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

 

#網易163(這個速度比較快)Ubuntu14

deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse

軟件源-分析

每一行的開頭的deb或者deb-src,分別表示通過.deb文件、源文件的方式進行安裝。URL後面的5個用空格隔開的字符串,分別對應相應的目錄結構。

1)當我們打開URL,比如Ubuntu14 的網易軟件源的,http://mirrors.163.com/ubuntu/ 會看到如下圖的目錄結構:

 

2)進入dists目錄,可以發現trusty、trusty-security、trusty-updates、trusty-proposed、trusty-backports 五個目錄:

3)trusty、trusty-security、trusty-updates、trusty-proposed、trusty-backports  後面四個字段對應子目錄:

deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse

 

細心對比後會發現以下規律:

系統版本 Ubuntu14 Ubuntu16 Ubuntu18
軟件源--關鍵字 trusty xenial bionic


5,更新源

sudo apt-get update

6. 更新軟件( 可選)

sudo apt-get dist-upgrade
sudo apt-get upgrade

  由於包與包之間存在各種依賴關係。upgrade只是簡單的更新包,不管這些依賴,它不和添加包,或是刪除包。而dist-upgrade可以根據依賴關係的變化,添加包,刪除包。

    upgrade:系統將現有的Package升級,如果有相依性的問題,而此相依性需要安裝其它新的Package或影響到其它Package的相依性時,此Package就不會被升級,會保留下來. dist-upgrade:可以聰明的解決相依性的問題,如果有相依性問題,需要安裝/移除新的Package,就會試着去安裝/移除它. (所以通常這個會被認爲是有點風險的升級) 

 

希望對你有幫助;

如果有更新或不對的地方歡迎指正。

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章