【转载】关于Linux中的apt-get的相关操作及原理

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

关于Linux中的apt-get的相关操作及原理
Linux下的apt-get指令与相关文件夹
apt-get是linux下的一种简便的安装和更新软件的方法,在装软件的时候常用的命令就是

sudo apt-get install <软件名>

下面介绍apt-get装软件的基本原理,首先,在本地有如下几个文件夹:
/var/cache/apt/archives
这个是利用apt-get install命令安装软件的临时存放软件包的位置
/var/lib/apt/lists
这个是用来存放已安装和未安装的软件列表的位置。我们用apt-get install的时候,实际上是从镜像源上下载软件,而镜像源的软件列表就存在这个lists文件中。通过apt-get update,就可以根据镜像源更新软件列表。
/etc/apt/source.list
这个用来存放软件源站点目录,当我们执行apt-get install 的时候,实际上就是去这些站点下载的软件包。而且,这个文件的内容我们可以自己修改,因为有些源站点可能会被墙,所以可以修改为国内的一些镜像源。上面的那个lists文件里面放的那些软件列表,就是从source.list中给出的站点上找到的。

这里用的是大清的软件源,长这样:

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

在下载软件的时候,我们通常先要进行软件列表的更新:

sudo apt-get update

这个指令执行的是从source.list中按照里面的软件源的地址对lists中的软件列表进行更新。这样可以使得本机上的列表和服务器上的一样,以便可以成功的安装。

更新完成以后我们使用 install 命令进行安装,首先,会对lists中的软件列表进行扫描,找到最新版本的软件包,然后检查依赖项,找到支持该软件运行的依赖软件包,然后从source.list指定的镜像站点中下载所需软件包,并解压,自动完成配置。

如果想要卸载某个已经安装的软件,有

sudo apt-get install <软件名>-

在软件名后面加一个连接符,这样可以同时执行安装和卸载
也可以用

sudo apt-get remove <软件名>

效果是一样的

还有其他一些命令:

sudo apt-get remove <软件名>+

上面这个可以用来安装,和install后面带减号对应,remove后面带加号表示安装。

sudo apt-cache search <软件名关键字>

上面是查找部分包含关键字的软件包。

sudo apt-get source <源码包名>

上面是下载软件包的源码。

sudo apt-get upgrade

上面这个也是一个很实用的命令,可以用来将系统中所有的软件包一次性升级到最新版本。它会列出所需升级的包,然后进行升级。和update不同,update仅仅是通过软件源来更新本地列表,而upgrade是对软件包进行升级。

sudo apt-get clean

上面的是清理所有缓存文件,即在/var/cache/apt/archives/ 和 /var/cache/apt/archives/partial/中的没有lock的文件。

sudo apt-get autoclean

上面这个只是清理低版本的文件,也就是说只有当有了更高版本的时候才会清理掉某个文件。

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

上面这个是完全卸载软件,并且删除配置。

镜像软件源 sources.list 的配置
Ubuntu采用集中式软件仓库机制,将软件都放置于仓库中,并设置多个镜像服务器,这样所有的ubuntu用户都可以随时获得最新的软件包,这些镜像服务器成为软件源,即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 后面跟的就是镜像服务器的地址,deb-src指的是源文件的地址。xenial 指的是Ubuntu的版本号的codename,因为本机是16.04版本,因此对应于xenial,后面详述。xenial-security,xenial-backports等是子目录的名字。

然后 main restricted 等是软件的不同类别,一般来说,有以下四种:

main:完全的自由软件。
restricted:不完全的自由软件。
universe:ubuntu官方不提供支持与补丁,全靠社区支持。
muitiverse:非自由软件,完全不提供支持和补丁。
上面这个展示的是清华大学软件源的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

北理工的,教育网适用。

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

这个是Ubuntu的官方源,国内较慢:

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

网易163的源。

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

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

然后直接将上述的内容替换掉sources.list的内容即可。(当然,codename要根据系统的版本替换掉,即上面的trusty等)

关于Ubuntu的Codename
上面讲到xenial是Ubuntu当前版本的codename。查看本机codename的方法如下:

lsb_release -a

其中 lsb 代表 linux standard base ,结果如下:

可以看到,codename是xenial,实际上全名叫做 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的版本六个月一次更新,一般分别于一年中的4月和10月发布,因此版本号中如16.04代表2016年4月的版本。而且,每两年会有一个LTS,long term support ,长期支持版本。比如 14.04 LTS,16.04 LTS等。而codename是每当发布一版Ubuntu,都会给它起一个小名,都是两个首字母相同的单词,然后都是动物。从6.06开始,首字母依次递增,现在已经增至xenial,即X了。据说18年4月的版本叫做 “Bionic Beaver”,意即“仿生河狸”。又回到了B。

下面是从6.06开始的每个版本的codename及其翻译:

16.04 LTS Xenial Xerus 好客的非洲地松鼠
15.10 Wily Werewolf 狡诈的狼人
15.04 Vivid Vervet 活泼的绿长尾猴
14.10 Utopic Unicorn 乌托邦独角兽
14.04 LTS Trusty Tahr 可靠的塔尔羊
13.10 Saucy Salamander 粗鲁的蝾螈
13.04 Raring Ringtail 卯足了劲的猫熊
12.10 Quantal Quetzal 缤纷的绿咬鹃
12.04 LTS Precise Pangolin 精准的穿山甲
11.10 Oneiric Ocelot 梦的虎猫
11.04 Natty Narwhal 敏捷的独角鲸
10.10 Maverick Meerkat 标新立异的的狐獴
10.04 LTS Lucid Lynx 清醒的猞猁
9.10 Karmic Koala 幸运的考拉
9.04 Jaunty Jackalope 活泼的鹿角兔
8.10 Intrepid Ibex 勇敢的野山羊
8.04 LTS Hardy Heron 坚强的苍鹭
7.10 Gutsy Gibbon 勇敢的长臂猿
7.04 Feisty Fawn 顽强的小鹿
6.10 Edgy Eft 锐利的蜥蜴
6.06 LTS Dapper Drake 整洁的公鸭

前述的需要替换的codename就是每一个代号的前面一个单词。常见的几版,如trusty和precise以及xenial是较新的几个LTS版。

THE END

作者:江户川柯壮
来源:CSDN
原文:https://blog.csdn.net/edogawachia/article/details/79263531
版权声明:本文为博主原创文章,转载请附上博文链接!

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,390评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,821评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,632评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,170评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,033评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,098评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,511评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,204评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,479评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,572评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,341评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,893评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,171评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,486评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,676评论 2 335

推荐阅读更多精彩内容