天天看點

ubuntu18.04配置apt源

1.備份源檔案

我們要修改的檔案是sources.list,它在目錄/etc/apt/下,sources.list是包管理工具apt所用的記錄軟體包倉庫位置的配置檔案,同樣類型的還有位于同目錄下sources.list.d檔案下的各種.list字尾的各檔案。

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

2.編輯源清單檔案

sudo vim /etc/apt/sources.list      

如果報錯:sudo:vim:command not found 說明沒裝vim編輯器

sudo apt-get install vim      

3.檢視新版本資訊

其實Ubuntu18.04版之前的任一版更改apt源為國内源方法早就有了,内容大同小異,我們應當掌握其規律了,其實每一版内容不同的地方就是版本号(或者官方一點的說:系統代号),是以我們先了解下新版本的系統代号:

root@xirang:~# lsb_release -c
Codename: bionic      

我們可以看到新版本的Ubuntu系統代号為bionic

同樣的我們也可以得到之前任意版本的系統代号:

Ubuntu 12.04 (LTS)代号為precise。

Ubuntu 14.04 (LTS)代号為trusty。

Ubuntu 15.04 代号為vivid。

Ubuntu 15.10 代号為wily。

Ubuntu 16.04 (LTS)代号為xenial。

是以這也就解釋了為什麼我們百度出來的那麼多方案裡面内容不盡相同的原因,因為他們更改apt安裝源時用的系統不一樣。

4.将原有的内容注釋掉,添加以下内容

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      
deb http://site.example.com/debian distribution component1 component2 component3
deb-src http://site.example.com/debian distribution component1 component2 component3
是以後面幾個參數是對軟體包的分類(Ubuntu下是main, restricted,universe ,multiverse這四個)
是以你把内容寫成
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed universe multiverse
之類的也是可以的,之前我有這個疑惑,是以在這裡一并告知和我有一樣疑惑的朋友。      
sudo apt-get update      
sudo apt-get upgrade