天天看點

ubuntu更換軟體源一、關于source.list檔案二、源的選擇 三、操作步驟四、關于更新軟體

目錄

一、關于source.list檔案

二、源的選擇

三、操作步驟

1、備份原始檔案

2、更改軟體源

3、更新源清單資訊

四、關于更新軟體

一、關于source.list檔案

    檔案/etc/apt/sources.list是一個普通可編輯的文本檔案,儲存了ubuntu軟體更新的源伺服器的位址。和sources.list功能一樣的是/etc/apt/sources.list.d/*.list(*代表一個檔案名,隻能由字母、數字、下劃線、英文句号組成)。sources.list.d目錄下的*.list檔案為在單獨檔案中寫入源的位址提供了一種方式,通常用來安裝第三方的軟體。

    source.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更換軟體源一、關于source.list檔案二、源的選擇 三、操作步驟四、關于更新軟體

更多内容可以使用man source.list獲得。

3、關于字首precise/trusty等差別,是指不同的版本代号

系統代号 版本
precise 12.04
trusty 14.04
vivid 15.04
xenial 16.04
zesty 17.04

檢視本機版本代号:

[email protected]:/etc/apt$ lsb_release -a
No LSB modules are available.
Distributor ID:        Ubuntu                
Description:           Ubuntu 12.04.5 LTS    
Release:               12.04                 
Codename:              precise               
           

二、源的選擇

    ubuntu官方有自身的軟體源,直接從官方的軟體源擷取資料的速度比較慢。而通過國内的一些的源的鏡像進行更新一般能夠獲得比官方源更快的速度,不過不同國内的源的下載下傳速度也會不一樣。

    該連結給出了詳細的軟體源資訊:   http://wiki.ubuntu.org.cn/%E6%BA%90%E5%88%97%E8%A1%A8

對比aliyun、sohu、ubuntu官方ping的資料,可以發現aliyun的源在時延上表現最好。

ubuntu更換軟體源一、關于source.list檔案二、源的選擇 三、操作步驟四、關于更新軟體

三、操作步驟

1、備份原始檔案

如果目前使用者無權限需要切換使用者

[email protected]:/etc/apt$ su root
Password: 
[email protected]:/etc/apt# cp /etc/apt/sources.list /etc/apt/sources.list.bak
[email protected]:/etc/apt# ls
apt.conf.d  preferences.d  sources.list  sources.list.bak  sources.list.d  trustdb.gpg  trusted.gpg  trusted.gpg~  trusted.gpg.d
           

2、更改軟體源

# 覆寫sources.list内容
[email protected]:/home/picasso# cat >/etc/apt/sources.list << END
> deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
> END

# 檢視sources.list内容
[email protected]:/home/picasso# cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse

# 檢視sources.list.bak内容對比
[email protected]:/home/picasso# cat /etc/apt/sources.list.bak
#deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Release i386 (20120423)]/ precise main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ precise main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ precise main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ precise-updates main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ precise-updates main restricted

## ... source.list.bak備份檔案内容過多不再贅述

           

3、更新源清單資訊

ubuntu更換軟體源一、關于source.list檔案二、源的選擇 三、操作步驟四、關于更新軟體

四、關于更新軟體

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

    由于包與包之間存在各種依賴關系。upgrade隻是簡單的更新包,不管這些依賴,它不添加包,或是删除包。而dist-upgrade可以根據依賴關系的變化,添加包,删除包。upgrade:系統将現有的Package更新,如果有相依性的問題,而此相依性需要安裝其它新的Package或影響到其它Package的相依性時,此Package就不會被更新,會保留下來. dist-upgrade:可以聰明的解決相依性的問題,如果有相依性問題,需要安裝/移除新的Package,就會試着去安裝/移除它. (是以通常這個會被認為是有點風險的更新) 

參考内容:https://www.jianshu.com/p/dd233020c5b7

繼續閱讀