關(guān)于Linux中的apt-get的相關(guān)操作及原理

轉(zhuǎn)自:江戶川柯壯 https://blog.csdn.net/edogawachia/article/details/79263531

Linux下的apt-get指令與相關(guān)文件夾

apt-get是linux下的一種簡(jiǎn)便的安裝和更新軟件的方法,在裝軟件的時(shí)候常用的命令就是

sudo apt-get install <軟件名>

下面介紹apt-get裝軟件的基本原理,首先,在本地有如下幾個(gè)文件夾:

/var/cache/apt/archives

這個(gè)是利用apt-get install命令安裝軟件的臨時(shí)存放軟件包的位置

<center>


這里寫圖片描述

</center>

/var/lib/apt/lists

這個(gè)是用來存放已安裝和未安裝的軟件列表的位置。我們用apt-get install的時(shí)候,實(shí)際上是從鏡像源上下載軟件,而鏡像源的軟件列表就存在這個(gè)lists文件中。通過apt-get update,就可以根據(jù)鏡像源更新軟件列表。

<center>


這里寫圖片描述

</center>

/etc/apt/source.list

這個(gè)用來存放軟件源站點(diǎn)目錄,當(dāng)我們執(zhí)行apt-get install 的時(shí)候,實(shí)際上就是去這些站點(diǎn)下載的軟件包。而且,這個(gè)文件的內(nèi)容我們可以自己修改,因?yàn)橛行┰凑军c(diǎn)可能會(huì)被墻,所以可以修改為國內(nèi)的一些鏡像源。上面的那個(gè)lists文件里面放的那些軟件列表,就是從source.list中給出的站點(diǎn)上找到的。

<center>


這里寫圖片描述

</center>

這里用的是大清的軟件源,長(zhǎng)這樣:

<center>


這里寫圖片描述

</center>

apt-get install 等命令的基本原理

在下載軟件的時(shí)候,我們通常先要進(jìn)行軟件列表的更新:

sudo apt-get update

這個(gè)指令執(zhí)行的是從source.list中按照里面的軟件源的地址對(duì)lists中的軟件列表進(jìn)行更新。這樣可以使得本機(jī)上的列表和服務(wù)器上的一樣,以便可以成功的安裝。

更新完成以后我們使用 install 命令進(jìn)行安裝,首先,會(huì)對(duì)lists中的軟件列表進(jìn)行掃描,找到最新版本的軟件包,然后檢查依賴項(xiàng),找到支持該軟件運(yùn)行的依賴軟件包,然后從source.list指定的鏡像站點(diǎn)中下載所需軟件包,并解壓,自動(dòng)完成配置。

如果想要卸載某個(gè)已經(jīng)安裝的軟件,有

sudo apt-get install <軟件名>-

在軟件名后面加一個(gè)連接符,這樣可以同時(shí)執(zhí)行安裝和卸載

<center>


這里寫圖片描述

</center>

也可以用

sudo apt-get remove <軟件名>

效果是一樣的

<center>


這里寫圖片描述

</center>

還有其他一些命令:

sudo apt-get remove <軟件名>+

上面這個(gè)可以用來安裝,和install后面帶減號(hào)對(duì)應(yīng),remove后面帶加號(hào)表示安裝。

sudo apt-cache search <軟件名關(guān)鍵字>

上面是查找部分包含關(guān)鍵字的軟件包。

sudo apt-get source <源碼包名>

上面是下載軟件包的源碼。

sudo apt-get upgrade

上面這個(gè)也是一個(gè)很實(shí)用的命令,可以用來將系統(tǒng)中所有的軟件包一次性升級(jí)到最新版本。它會(huì)列出所需升級(jí)的包,然后進(jìn)行升級(jí)。和update不同,update僅僅是通過軟件源來更新本地列表,而upgrade是對(duì)軟件包進(jìn)行升級(jí)。

<center>


這里寫圖片描述

</center>

sudo apt-get clean

上面的是清理所有緩存文件,即在/var/cache/apt/archives/ 和 /var/cache/apt/archives/partial/中的沒有l(wèi)ock的文件。

sudo apt-get autoclean

上面這個(gè)只是清理低版本的文件,也就是說只有當(dāng)有了更高版本的時(shí)候才會(huì)清理掉某個(gè)文件。

sudo apt-get --purge remove <軟件名>

上面這個(gè)是完全卸載軟件,并且刪除配置。

鏡像軟件源 sources.list 的配置

Ubuntu采用集中式軟件倉庫機(jī)制,將軟件都放置于倉庫中,并設(shè)置多個(gè)鏡像服務(wù)器,這樣所有的ubuntu用戶都可以隨時(shí)獲得最新的軟件包,這些鏡像服務(wù)器成為軟件源,即repository。

sources.list的格式如下:

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

deb 后面跟的就是鏡像服務(wù)器的地址,deb-src指的是源文件的地址。xenial 指的是Ubuntu的版本號(hào)的codename,因?yàn)楸緳C(jī)是16.04版本,因此對(duì)應(yīng)于xenial,后面詳述。xenial-security,xenial-backports等是子目錄的名字。

<center>


這里寫圖片描述

</center>

然后 main restricted 等是軟件的不同類別,一般來說,有以下四種:

  • main:完全的自由軟件。
  • restricted:不完全的自由軟件。
  • universe:ubuntu官方不提供支持與補(bǔ)丁,全靠社區(qū)支持。
  • muitiverse:非自由軟件,完全不提供支持和補(bǔ)丁。

上面這個(gè)展示的是清華大學(xué)軟件源的sources.list配置,還有其他可供選擇的:

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

這是阿里云的源。

deb http://debian.ustc.edu.cn/ubuntu/ trusty main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ trusty-backports main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ trusty-proposed main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ trusty-security main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ trusty-updates main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty-backports main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty-proposed main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty-security main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ trusty-updates main multiverse restricted universe

中科大的。

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

搜狐的。

deb http://mirror.bit.edu.cn/ubuntu/ precise main restricted universe multiverse
deb http://mirror.bit.edu.cn/ubuntu/ precise-security main restricted universe multiverse
deb http://mirror.bit.edu.cn/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirror.bit.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb http://mirror.bit.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirror.bit.edu.cn/ubuntu/ precise main restricted universe multiverse
deb-src http://mirror.bit.edu.cn/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirror.bit.edu.cn/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirror.bit.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirror.bit.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse

北理工的,教育網(wǎng)適用。

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

這個(gè)是Ubuntu的官方源,國內(nèi)較慢:

<center>


這里寫圖片描述

</center>

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

網(wǎng)易163的源。

其他的可以自行查找,若要更新sources.list建議先備份,如下:

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

然后直接將上述的內(nèi)容替換掉sources.list的內(nèi)容即可。(當(dāng)然,codename要根據(jù)系統(tǒng)的版本替換掉,即上面的trusty等)

關(guān)于Ubuntu的Codename

上面講到xenial是Ubuntu當(dāng)前版本的codename。查看本機(jī)codename的方法如下:

lsb_release -a

其中 lsb 代表 linux standard base ,結(jié)果如下:

<center>


這里寫圖片描述

</center>

可以看到,codename是xenial,實(shí)際上全名叫做 Xenial Xerus ,意思是好客的非洲地松鼠。

16.04的codename的來歷是這樣的:

“What fortunate timing that our next LTS should be X, because “xenial” means “friendly relations between hosts and guests”, and given all the amazing work going into LXD and KVM for Ubuntu OpenStack, and beyond that the interoperability of Ubuntu OpenStack with hypervisors of all sorts, it seems like a perfect fit.

And Xerus, the African ground squirrels, are among the most social animals in my home country. They thrive in the desert, they live in small, agile, social groups that get along unusually well with their neighbours (for most mammals, neighbours are a source of bloody competition, for Xerus, hey, collaboration is cool). They are fast, feisty, friendly and known for their enormous… courage. That sounds just about right. With great… courage… comes great opportunity!”

—— Mark Shuttleworth

Ubuntu的版本六個(gè)月一次更新,一般分別于一年中的4月和10月發(fā)布,因此版本號(hào)中如16.04代表2016年4月的版本。而且,每?jī)赡陼?huì)有一個(gè)LTS,long term support ,長(zhǎng)期支持版本。比如 14.04 LTS,16.04 LTS等。而codename是每當(dāng)發(fā)布一版Ubuntu,都會(huì)給它起一個(gè)小名,都是兩個(gè)首字母相同的單詞,然后都是動(dòng)物。從6.06開始,首字母依次遞增,現(xiàn)在已經(jīng)增至xenial,即X了。據(jù)說18年4月的版本叫做 “Bionic Beaver”,意即“仿生河貍”。又回到了B。

下面是從6.06開始的每個(gè)版本的codename及其翻譯:

16.04 LTS Xenial Xerus 好客的非洲地松鼠
15.10 Wily Werewolf 狡詐的狼人
15.04 Vivid Vervet 活潑的綠長(zhǎng)尾猴
14.10 Utopic Unicorn 烏托邦獨(dú)角獸
14.04 LTS Trusty Tahr 可靠的塔爾羊
13.10 Saucy Salamander 粗魯?shù)南旙?br> 13.04 Raring Ringtail 卯足了勁的貓熊
12.10 Quantal Quetzal 繽紛的綠咬鵑
12.04 LTS Precise Pangolin 精準(zhǔn)的穿山甲
11.10 Oneiric Ocelot 夢(mèng)的虎貓
11.04 Natty Narwhal 敏捷的獨(dú)角鯨
10.10 Maverick Meerkat 標(biāo)新立異的的狐獴
10.04 LTS Lucid Lynx 清醒的猞猁
9.10 Karmic Koala 幸運(yùn)的考拉
9.04 Jaunty Jackalope 活潑的鹿角兔
8.10 Intrepid Ibex 勇敢的野山羊
8.04 LTS Hardy Heron 堅(jiān)強(qiáng)的蒼鷺
7.10 Gutsy Gibbon 勇敢的長(zhǎng)臂猿
7.04 Feisty Fawn 頑強(qiáng)的小鹿
6.10 Edgy Eft 銳利的蜥蜴
6.06 LTS Dapper Drake 整潔的公鴨

前述的需要替換的codename就是每一個(gè)代號(hào)的前面一個(gè)單詞。常見的幾版,如trusty和precise以及xenial是較新的幾個(gè)LTS版。

</article>

</main>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容