用dpkg命令在Debian系的Linux系統(tǒng)中管理軟件包
dpkg 意即 Debian 包管理器(Debian PacKaGe manager)。dpkg 是一個可以安裝、構(gòu)建、刪除及管理 Debian 軟件包的命令行工具。dpkg 將 Aptitude(***而更用戶友好)作為執(zhí)行所有操作的前端界面。
其它的一些工具如 dpkg-deb 和 dpkg-query 等也使用 dpkg 作為執(zhí)行某些操作的前端。
現(xiàn)在大多數(shù)系統(tǒng)管理員使用 Apt、Apt-Get 及 Aptitude 等工具,不用費心就可以輕松地管理軟件。
盡管如此,必要的時候還是需要用 dpkg 來安裝某些軟件。其它的一些在 Linux 系統(tǒng)上廣泛使用的包管理工具還有 yum、dnf、apt-get、rpm、Zypper、pacman、urpmi 等等。
現(xiàn)在,我要在裝有 Ubuntu 15.10 的機器上用一些實例講解最常用的 dpkg 命令。
1) dpkg 常見命令的語法及 dpkg 文件位置
下面是 dpkg 常見命令的語法及 dpkg 相關(guān)文件的位置,如果想深入了解,這些對你肯定大有益處。
- ### dpkg 命令的語法
 - $ dpkg -[command] [.deb package name]
 - $ dpkg -[command] [package name]
 - ### dpkg 相關(guān)文件的位置
 - $ /var/lib/dpkg
 - ### 這個文件包含了被 dpkg 命令(install、remove 等)所修改的包的信息
 - $ /var/lib/dpkg/status
 - ### 這個文件包含了可用包的列表
 - $ /var/lib/dpkg/status
 
2) 安裝/升級軟件
在基于 Debian 的系統(tǒng)里,比如 Debian、Mint、Ubuntu 和 elementryOS,用以下命令來安裝/升級 .deb 軟件包。這里我要用 atom-amd64.deb 文件安裝 Atom。要是已經(jīng)安裝了 Atom,就會升級它。要么就會安裝一個新的 Atom。
- ### 安裝或升級 dpkg 軟件包
 - $ sudo dpkg -i atom-amd64.deb
 - Selecting previously unselected package atom.
 - (Reading database ... 426102 files and directories currently installed.)
 - Preparing to unpack atom-amd64.deb ...
 - Unpacking atom (1.5.3) over (1.5.3) ...
 - Setting up atom (1.5.3) ...
 - Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
 - Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
 - Rebuilding /usr/share/applications/bamf-2.index...
 - Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
 - Processing triggers for mime-support (3.58ubuntu1) ...
 
3) 從文件夾里安裝軟件
在基于 Debian 的系統(tǒng)里,用下列命令從目錄中逐個安裝軟件。這會安裝 /opt/software 目錄下的所有以 .deb 為后綴的軟件。
- $ sudo dpkg -iR /opt/software
 - Selecting previously unselected package atom.
 - (Reading database ... 423303 files and directories currently installed.)
 - Preparing to unpack /opt/software/atom-amd64.deb ...
 - Unpacking atom (1.5.3) ...
 - Setting up atom (1.5.3) ...
 - Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
 - Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
 - Rebuilding /usr/share/applications/bamf-2.index...
 - Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
 - Processing triggers for mime-support (3.58ubuntu1) ...
 
4) 顯示已安裝軟件列表
以下命令可以列出 Debian 系的系統(tǒng)中所有已安裝的軟件,同時會顯示軟件版本和描述信息。
- $ dpkg -l
 - Desired=Unknown/Install/Remove/Purge/Hold
 - | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
 - |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
 - ||/ Name Version Architecture Description
 - +++-===========================-==================================-============-================================================================
 - ii account-plugin-aim 3.12.10-0ubuntu2 amd64 Messaging account plugin for AIM
 - ii account-plugin-facebook 0.12+15.10.20150723-0ubuntu1 all GNOME Control Center account plugin for single signon - facebook
 - ii account-plugin-flickr 0.12+15.10.20150723-0ubuntu1 all GNOME Control Center account plugin for single signon - flickr
 - ii account-plugin-google 0.12+15.10.20150723-0ubuntu1 all GNOME Control Center account plugin for single signon
 - ii account-plugin-jabber 3.12.10-0ubuntu2 amd64 Messaging account plugin for Jabber/XMPP
 - ii account-plugin-salut 3.12.10-0ubuntu2 amd64 Messaging account plugin for Local XMPP (Salut)
 - .
 - .
 
5) 查看指定的已安裝軟件
用以下命令列出指定的一個已安裝軟件,同時會顯示軟件版本和描述信息。
- $ dpkg -l atom
 - Desired=Unknown/Install/Remove/Purge/Hold
 - | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
 - |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
 - ||/ Name Version Architecture Description
 - +++-==========-=========-===================-============================================
 - ii atom 1.5.3 amd64 A hackable text editor for the 21st Century.
 
6) 查看軟件安裝目錄
以下命令可以在基于 Debian 的系統(tǒng)上查看軟件的安裝路徑。
- $ dpkg -L atom
 - /.
 - /usr
 - /usr/bin
 - /usr/bin/atom
 - /usr/share
 - /usr/share/lintian
 - /usr/share/lintian/overrides
 - /usr/share/lintian/overrides/atom
 - /usr/share/pixmaps
 - /usr/share/pixmaps/atom.png
 - /usr/share/doc
 
7) 查看 deb 包內(nèi)容
下列命令可以查看 deb 包內(nèi)容。它會顯示 .deb 包中的一系列文件。
- $ dpkg -c atom-amd64.deb
 - drwxr-xr-x root/root 0 2016-02-13 02:13 ./
 - drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/
 - drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/bin/
 - -rwxr-xr-x root/root 3067 2016-02-13 02:13 ./usr/bin/atom
 - drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/
 - drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/lintian/
 - drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/lintian/overrides/
 - -rw-r--r-- root/root 299 2016-02-13 02:13 ./usr/share/lintian/overrides/atom
 - drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/pixmaps/
 - -rw-r--r-- root/root 643183 2016-02-13 02:13 ./usr/share/pixmaps/atom.png
 - drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/doc/
 - .
 - .
 
8) 顯示軟件的詳細信息
以下命令可以顯示軟件的詳細信息,如軟件名、軟件類別、版本、維護者、軟件架構(gòu)、依賴的軟件、軟件描述等等。
- $ dpkg -s atom
 - Package: atom
 - Status: install ok installed
 - Priority: optional
 - Section: devel
 - Installed-Size: 213496
 - Maintainer: GitHub <atom@github.com>Architecture: amd64
 - Version: 1.5.3
 - Depends: git, gconf2, gconf-service, libgtk2.0-0, libudev0 | libudev1, libgcrypt11 | libgcrypt20, libnotify4, libxtst6, libnss3, python, gvfs-bin, xdg-utils, libcap2
 - Recommends: lsb-release
 - Suggests: libgnome-keyring0, gir1.2-gnomekeyring-1.0
 - Description: A hackable text editor for the 21st Century.
 - Atom is a free and open source text editor that is modern, approachable, and hackable to the core.</atom@github.com>
 
9) 查看文件屬于哪個軟件
用以下命令來查看文件屬于哪個軟件。
- $ dpkg -S /usr/bin/atom
 - atom: /usr/bin/atom
 
10) 移除/刪除軟件
以下命令可以用來移除/刪除一個已經(jīng)安裝的軟件,但不刪除配置文件。
- $ sudo dpkg -r atom
 - (Reading database ... 426404 files and directories currently installed.)
 - Removing atom (1.5.3) ...
 - Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
 - Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
 - Rebuilding /usr/share/applications/bamf-2.index...
 - Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
 - Processing triggers for mime-support (3.58ubuntu1) ...
 
11) 清除軟件
以下命令可以用來移除/刪除包括配置文件在內(nèi)的所有文件。
- $ sudo dpkg -P atom
 - (Reading database ... 426404 files and directories currently installed.)
 - Removing atom (1.5.3) ...
 - Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
 - Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
 - Rebuilding /usr/share/applications/bamf-2.index...
 - Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
 - Processing triggers for mime-support (3.58ubuntu1) ...
 
12) 了解更多
用以下命令來查看更多關(guān)于 dpkg 的信息。
- $ dpkg -help
 - 或
 - $ man dpkg
 
開始體驗 dpkg 吧。















 
 
 








 
 
 
 