赞
踩
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中给出的站点上找到的。
这里用的是大清的软件源,长这样:
在下载软件的时候,我们通常先要进行软件列表的更新:
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 <软件名>
上面这个是完全卸载软件,并且删除配置。
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 等是软件的不同类别,一般来说,有以下四种:
上面这个展示的是清华大学软件源的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等)
上面讲到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
2018.02.05 周一 19:32 pm
在石榴花丛中,那里有光,有酒,有石榴花。你不来的话,这一切都了无意义。你来了的话,这一切也会变得了无意义。 —— 莫拉维·鲁米
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。