【轉(zhuǎn)載】關(guān)于Linux中的apt-get的相關(guān)操作及原理

原文鏈接:https://blog.csdn.net/edogawachia/article/details/79263531

關(guān)于Linux中的apt-get的相關(guān)操作及原理
Linux下的apt-get指令與相關(guān)文件夾
apt-get是linux下的一種簡便的安裝和更新軟件的方法,在裝軟件的時(shí)候常用的命令就是

sudo apt-get install <軟件名>

下面介紹apt-get裝軟件的基本原理,首先,在本地有如下幾個(gè)文件夾:
/var/cache/apt/archives
這個(gè)是利用apt-get install命令安裝軟件的臨時(shí)存放軟件包的位置
/var/lib/apt/lists
這個(gè)是用來存放已安裝和未安裝的軟件列表的位置。我們用apt-get install的時(shí)候晚顷,實(shí)際上是從鏡像源上下載軟件辆童,而鏡像源的軟件列表就存在這個(gè)lists文件中盔性。通過apt-get update划址,就可以根據(jù)鏡像源更新軟件列表。
/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)可能會被墻怔昨,所以可以修改為國內(nèi)的一些鏡像源雀久。上面的那個(gè)lists文件里面放的那些軟件列表,就是從source.list中給出的站點(diǎn)上找到的趁舀。

這里用的是大清的軟件源赖捌,長這樣:

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

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

sudo apt-get update

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

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

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

sudo apt-get install <軟件名>-

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

sudo apt-get remove <軟件名>

效果是一樣的

還有其他一些命令:

sudo apt-get remove <軟件名>+

上面這個(gè)可以用來安裝,和install后面帶減號對應(yīng)此衅,remove后面帶加號表示安裝强戴。

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

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

sudo apt-get source <源碼包名>

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

sudo apt-get upgrade

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

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í)候才會清理掉某個(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的版本號的codename但荤,因?yàn)楸緳C(jī)是16.04版本罗岖,因此對應(yīng)于xenial,后面詳述腹躁。xenial-security呀闻,xenial-backports等是子目錄的名字。

然后 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)較慢:

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é)果如下:

可以看到策菜,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ā)布同衣,因此版本號中如16.04代表2016年4月的版本。而且壶运,每兩年會有一個(gè)LTS耐齐,long term support ,長期支持版本蒋情。比如 14.04 LTS埠况,16.04 LTS等。而codename是每當(dāng)發(fā)布一版Ubuntu棵癣,都會給它起一個(gè)小名辕翰,都是兩個(gè)首字母相同的單詞,然后都是動物狈谊。從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 活潑的綠長尾猴
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 夢的虎貓
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 勇敢的長臂猿
7.04 Feisty Fawn 頑強(qiáng)的小鹿
6.10 Edgy Eft 銳利的蜥蜴
6.06 LTS Dapper Drake 整潔的公鴨

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

THE END

作者:江戶川柯壯
來源:CSDN
原文:https://blog.csdn.net/edogawachia/article/details/79263531
版權(quán)聲明:本文為博主原創(chuàng)文章喳篇,轉(zhuǎn)載請附上博文鏈接!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末态辛,一起剝皮案震驚了整個(gè)濱河市麸澜,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌因妙,老刑警劉巖痰憎,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異攀涵,居然都是意外死亡铣耘,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進(jìn)店門以故,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蜗细,“玉大人,你說我怎么就攤上這事怒详÷剑” “怎么了?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵昆烁,是天一觀的道長吊骤。 經(jīng)常有香客問我,道長静尼,這世上最難降的妖魔是什么白粉? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮鼠渺,結(jié)果婚禮上鸭巴,老公的妹妹穿的比我還像新娘。我一直安慰自己拦盹,他們只是感情好鹃祖,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著普舆,像睡著了一般恬口。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上沼侣,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天楷兽,我揣著相機(jī)與錄音,去河邊找鬼华临。 笑死芯杀,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播揭厚,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼却特,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了筛圆?” 一聲冷哼從身側(cè)響起裂明,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎太援,沒想到半個(gè)月后闽晦,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡提岔,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年仙蛉,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片碱蒙。...
    茶點(diǎn)故事閱讀 40,133評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡荠瘪,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出赛惩,到底是詐尸還是另有隱情哀墓,我是刑警寧澤,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布喷兼,位于F島的核電站篮绰,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏季惯。R本人自食惡果不足惜吠各,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望星瘾。 院中可真熱鬧,春花似錦惧辈、人聲如沸琳状。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽念逞。三九已至,卻和暖如春边翁,著一層夾襖步出監(jiān)牢的瞬間翎承,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工符匾, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留叨咖,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像甸各,于是被迫代替她去往敵國和親垛贤。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評論 2 355

推薦閱讀更多精彩內(nèi)容