1. 程式人生 > >Ubuntu18.04下更改apt源為阿里雲源

Ubuntu18.04下更改apt源為阿里雲源

前言:看見Ubuntu新出了18.04版本感覺不錯,裝一個玩玩,雖然有很多教程可以參考,但我也給出一個不是很一樣的方案吧,儘量解釋的詳細一點。

為了下載更方便,速度更快,我們往往在使用Linux系列系統時修改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源為國內源方法早就有了,內容大同小異,我們應當掌握其規律了,其實每一版內容不同的地方就是版本號(或者官方一點的說:系統代號),所以我們先了解下新版本的系統代號:

使用如下命令:

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這四個)

所以你把內容寫成

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

之類的也是可以的,之前我有這個疑惑,所以在這裡一併告知和我有一樣疑惑的朋友。

5.更新軟體列表

執行如下命令:

sudo apt-get update

6.更新軟體包

執行如下命令:

sudo apt-get upgrade

7.最後說兩句

關於sudo apt-get update與sudo apt-get upgrade有什麼區別,推薦一篇博文,一看就懂

https://blog.csdn.net/beckeyloveyou/article/details/51352426

在此表示感謝。