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源為國內源方法早就有了,內容大同小異,我們應當掌握其規律了,其實每一版內容不同的地方就是版本號(或者官方一點的說:系統代號),所以我們先了解下新版本的系統代號:
使用如下命令:
lsb_release -c
得到本系統的系統代號,如下圖所示:
我們可以看到新版本的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
值得注意的是sources.list文件的條目都是有格式的(通過上面的內容大家也看的出來),一般有如下形式
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這四個)
5.更新軟件列表
運行如下命令:
sudo apt-get update
6.更新軟件包
運行如下命令:
sudo apt-get upgrade