APT软件包管理工具(Debian和Raspbian系统)

简介

Advanced Packaging Tool(apt)是Linux下的一款安装包管理工具。

最初只有.tar.gz的打包文件,用户必须编译每个他想在GNU/Linux上运行的软件。用户们普遍认为系统很有必要提供一种方法来管理这些安装在机器上的软件包,当Debian诞生时,这样一个管理工具也就应运而生,它被命名为dpkg。从而著名的“package”概念第一次出现在GNU/Linux系统中,稍后Red Hat才决定开发自己的“rpm”包管理系统。

很快一个新的问题难倒了GNU/Linux制作者,他们需要一个快速、实用、高效的方法来安装软件包,当软件包更新时,这个工具应该能自动管理关联文件和维护已有配置文件。Debian再次率先解决了这个问题,APT(Advanced Packaging Tool)作为dpkg的前端诞生了。APT后来还被Conectiva改造用来管理rpm,并被其它Linux发行版本采用为它们的软件包管理工具。

APT由几个名字以“apt-”打头的程序组成。apt-get、apt-cache 和apt-cdrom是处理软件包的命令行工具。

源地址配置(/etc/apt/sources.list)

作为操作的一部分,APT使用一个文件列出可获得软件包的镜像站点地址,这个文件就是/etc/apt/sources.list。

root@raspberrypi:~# cat /etc/apt/sources.list
deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi

打开最后一行以deb-src开头的注释,我们可以获取软件包源代码。

搜索软件包(apt-cache search)

root@raspberrypi:/# apt-cache search vim 

更新源(apt-get update)

软件包列表并不是实时加载服务器端的列表。如果我们想要查看最新的软件包列表,就要使用apt-get update 命令获取最新的软件包列表。

root@raspberrypi:/# apt-get update 
Get:1 http://archive.raspberrypi.org/debian stretch InRelease [25.3 kB]                                            
Get:2 http://raspbian.raspberrypi.org/raspbian stretch InRelease [15.0 kB]                                         
Get:3 http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages [11.7 MB]
Get:4 http://archive.raspberrypi.org/debian stretch/main armhf Packages [145 kB]
Get:5 http://archive.raspberrypi.org/debian stretch/ui armhf Packages [30.8 kB]                                  
Fetched 11.9 MB in 1min 18s (152 kB/s)                                                                                                                                                                           
Reading package lists... Done

安装软件包(apt-get install)

root@raspberrypi:/# apt-get install vim
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libgpm2 vim-runtime
Suggested packages:
  gpm ctags vim-doc vim-scripts
The following NEW packages will be installed:
  libgpm2 vim vim-runtime
0 upgraded, 3 newly installed, 0 to remove and 2 not upgraded.
Need to get 6,231 kB of archives.
After this operation, 30.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.neusoft.edu.cn/raspbian/raspbian stretch/main armhf libgpm2 armhf 1.20.4-6.2 [33.0 kB]
Get:2 http://mirrors.neusoft.edu.cn/raspbian/raspbian stretch/main armhf vim-runtime all 2:8.0.0197-4+deb9u1 [5,407 kB]
Get:3 http://mirrors.neusoft.edu.cn/raspbian/raspbian stretch/main armhf vim armhf 2:8.0.0197-4+deb9u1 [790 kB]                                                                                                  
Fetched 6,231 kB in 10s (584 kB/s)                                                                                                                                                                               
Selecting previously unselected package libgpm2:armhf.
(Reading database ... 34360 files and directories currently installed.)
Preparing to unpack .../libgpm2_1.20.4-6.2_armhf.deb ...
Unpacking libgpm2:armhf (1.20.4-6.2) ...
Selecting previously unselected package vim-runtime.
Preparing to unpack .../vim-runtime_2%3a8.0.0197-4+deb9u1_all.deb ...
Adding 'diversion of /usr/share/vim/vim80/doc/help.txt to /usr/share/vim/vim80/doc/help.txt.vim-tiny by vim-runtime'
Adding 'diversion of /usr/share/vim/vim80/doc/tags to /usr/share/vim/vim80/doc/tags.vim-tiny by vim-runtime'
Unpacking vim-runtime (2:8.0.0197-4+deb9u1) ...
Selecting previously unselected package vim.
Preparing to unpack .../vim_2%3a8.0.0197-4+deb9u1_armhf.deb ...
Unpacking vim (2:8.0.0197-4+deb9u1) ...
Setting up libgpm2:armhf (1.20.4-6.2) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up vim-runtime (2:8.0.0197-4+deb9u1) ...
Setting up vim (2:8.0.0197-4+deb9u1) ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode

删除软件包(apt-get autoremove --purge)

apt-get autoremove --purge命令不仅会删除软件包,还会删除所有依赖以及配置文件。

所以使用此命令能够干净彻底的删除一个软件包及其相关配置。

更新已安装软件包(apt-get upgrade)

使用apt-get upgrade命令可以更新所有的软件包,也可以指定某一个软件包进行更新。

root@raspberrypi:/# apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  bluez-firmware wget
2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 892 kB of archives.
After this operation, 7,168 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.shu.edu.cn/raspbian/raspbian stretch/main armhf wget armhf 1.18-5+deb9u2 [768 kB]            
Get:2 http://archive.raspberrypi.org/debian stretch/main armhf bluez-firmware all 1.2-3+rpt5 [124 kB]                                                                                                            
Fetched 892 kB in 52s (16.9 kB/s)                                                                                                                                                                                
Reading changelogs... Done
(Reading database ... 36098 files and directories currently installed.)
Preparing to unpack .../wget_1.18-5+deb9u2_armhf.deb ...
Unpacking wget (1.18-5+deb9u2) over (1.18-5+deb9u1) ...
Preparing to unpack .../bluez-firmware_1.2-3+rpt5_all.deb ...
Unpacking bluez-firmware (1.2-3+rpt5) over (1.2-3+rpt4.1) ...
Setting up bluez-firmware (1.2-3+rpt5) ...
Processing triggers for install-info (6.3.0.dfsg.1-1+b1) ...
Setting up wget (1.18-5+deb9u2) ...
Processing triggers for man-db (2.7.6.1-2) ...

清理过时软件包(apt-get autoclean)

root@raspberrypi:/# apt-get autoclean
Reading package lists... Done
Building dependency tree       
Reading state information... Done

检查损坏依赖(apt-get check )

root@raspberrypi:/# apt-get check 
Reading package lists... Done
Building dependency tree       
Reading state information... Done

猜你喜欢

转载自my.oschina.net/u/3452433/blog/1813527