APT軟件包管理工具(Debian和Raspbian系統)

簡介

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

最初只有.tar.gz的打包文件,用戶必須編譯每一個他想在GNU/Linux上運行的軟件。用戶們廣泛認爲系統頗有必要提供一種方法來管理這些安裝在機器上的軟件包,當Debian誕生時,這樣一個管理工具也就應運而生,它被命名爲dpkg。從而著名的「package」概念第一次出如今GNU/Linux系統中,稍後Red Hat才決定開發本身的「rpm」包管理系統。vim

很快一個新的問題難倒了GNU/Linux製做者,他們須要一個快速、實用、高效的方法來安裝軟件包,當軟件包更新時,這個工具應該能自動管理關聯文件和維護已有配置文件。Debian再次率先解決了這個問題,APT(Advanced Packaging Tool)做爲dpkg的前端誕生了。APT後來還被Conectiva改造用來管理rpm,並被其它Linux發行版本採用爲它們的軟件包管理工具。服務器

APT由幾個名字以「apt-」打頭的程序組成。apt-get、apt-cache 和apt-cdrom是處理軟件包的命令行工具。ide

 

源地址配置(/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開頭的註釋,咱們能夠獲取軟件包源代碼。ui

 

搜索軟件包(apt-cache search)

root@raspberrypi:/# apt-cache search vim

 

更新源(apt-get update)

軟件包列表並非實時加載服務器端的列表。若是咱們想要查看最新的軟件包列表,就要使用apt-get update 命令獲取最新的軟件包列表。this

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命令不只會刪除軟件包,還會刪除全部依賴以及配置文件。spa

因此使用此命令可以乾淨完全的刪除一個軟件包及其相關配置。命令行

 

更新已安裝軟件包(apt-get upgrade)

使用apt-get upgrade命令能夠更新全部的軟件包,也能夠指定某一個軟件包進行更新。code

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
相關文章
相關標籤/搜索