Linux系统具有强大的包管理能力

描述

一、包管理基本原理

Linux系统具有强大的包管理能力,能够自动从互联网的软件仓库中搜索、安装、升级、卸载软件或操作系统。其基本原理为:

  1. 厂商或开源组织将软件包放至服务器中,构成源或软件仓库,以供用户下载使用;
  2. 软件仓库有很多,国内常用的源有阿里源、清华源等等。Ubuntu源信息记录在/etc/apt/sources.list中
root@linux:/var/lib/apt/lists$ cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic stable
# deb-src [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic stable
  1. 执行apt-get update命令,则会根据/etc/apt/sources.list记录的源站信息,扫描源服务器,并建立软件包的索引文件,存放在/var/lib/apt/lists/中
root@linux:/var/lib/apt/lists# ll
total 222044
drwxr-xr-x 4 root root    12288 Feb  7 10:17 ./
drwxr-xr-x 5 root root     4096 Nov 13  2020 ../
drwxr-xr-x 2 _apt root     4096 Nov 16  2020 auxfiles/
-rw-r----- 1 root root        0 Nov 16  2020 lock
-rw-r--r-- 1 root root    74562 Feb  7 07:11 mirrors.aliyun.com_ubuntu_dists_bionic-backports_InRelease
-rw-r--r-- 1 root root    59629 Dec 16 00:17 mirrors.aliyun.com_ubuntu_dists_bionic-backports_main_binary-amd64_Packages
-rw-r--r-- 1 root root    12910 Dec 16 00:17 mirrors.aliyun.com_ubuntu_dists_bionic-backports_main_i18n_Translation-en
-rw-r--r-- 1 root root    17863 Dec 16 00:17 mirrors.aliyun.com_ubuntu_dists_bionic-backports_main_source_Sources
-rw-r--r-- 1 root root    49624 Dec 16 02:14 mirrors.aliyun.com_ubuntu_dists_bionic-backports_universe_binary-amd64_Packages
-rw-r--r-- 1 root root    15723 Dec 16 02:14 mirrors.aliyun.com_ubuntu_dists_bionic-backports_universe_i18n_Translation-en
-rw-r--r-- 1 root root    20023 Dec 16 02:14 mirrors.aliyun.com_ubuntu_dists_bionic-backports_universe_source_Sources
-rw-r--r-- 1 root root   242048 Apr 27  2018 mirrors.aliyun.com_ubuntu_dists_bionic_InRelease
......

进一步,查看文件的信息,则:

root@linux:/var/lib/apt/lists# cat mirrors.aliyun.com_ubuntu_dists_bionic_InRelease | more
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512


Origin: Ubuntu
Label: Ubuntu
Suite: bionic
Version: 18.04
Codename: bionic
Date: Thu, 26 Apr 2018 23:37:48 UTC
Architectures: amd64 arm64 armhf i386 ppc64el s390x
Components: main restricted universe multiverse
Description: Ubuntu Bionic 18.04
MD5Sum:
 32a92a5c20f378d42dd2d2f4f28f6637        628836439 Contents-amd64
 53c6a594819b51a5755f88b45d1eff7f         37766986 Contents-arm64.gz
 cd7bf6d50403da4348ee48138eace986        585939706 Contents-ppc64el
 af42d07307c5d1398c75e28986b36509        616261664 Contents-i386
 98f43960ac7029b4948a13614038593c        584794633 Contents-armhf
 31848d4faedf11946ff1af9c281f4e6b         39528051 Contents-amd64.gz
  1. 执行apt-get install XXX,则会根据软件包的索引文件,找到最新版本的软件包及其依赖关系,下载(或更新)、解压、安装和配置软件包。
root@linux:/var/lib/apt/lists# apt-get install git
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  grub-pc-bin
Use 'apt autoremove' to remove it.
Suggested packages:
  git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn
The following packages will be upgraded:
  git
1 upgraded, 0 newly installed, 0 to remove and 315 not upgraded.
  1. 执行apt-get upgrade,则可以将所有软件包一次性升级到最新版本。
root@linux:/var/lib/apt/lists# apt-get upgrade
......
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...


done.
done.
Processing triggers for initramfs-tools (0.130ubuntu3.13) ...
update-initramfs: Generating /boot/initrd.img-4.15.0-122-generic

二、工具apt-get和apt区别:

  1. Ubuntu 16.04版本前,使用apt-get、apt-cache和apt-config进行包的管理;存在的问题:命令过于分散,并且apt-cache和apt-config用得比较少。
  2. Ubuntu 16.04版本发布时,引入apt命令以解决命令分散的问题;存在的问题:apt并未完全取代apt-get命令。
apt命令              原有命令             命令的功能
apt install       apt-get install        安装软件包
apt remove        apt-get remove         移除软件包
apt purge         apt-get purge          移除软件包及配置文件
apt update        apt-get update         刷新存储库索引
apt upgrade       apt-get upgrade        升级所有可升级的软件包
apt autoremove    apt-get autoremove     自动删除不需要的包
apt full-upgrade  apt-get dist-upgrade   在升级软件包时自动处理依赖关系
apt search        apt-cache search       搜索应用程序
apt show          apt-cache show         显示安装细节
打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分