閱讀97 返回首頁    go 阿裏雲 go 技術社區[雲棲]


用 dpkg 命令在 Debian 係的 Linux係統中管理軟件包

dpkg 意即 Debian 包管理器Debian PacKaGe manager。dpkg 是一個可以安裝、構建、刪除及管理 Debian 軟件包的命令行工具。dpkg 將 Aptitude(首選而更用戶友好)作為執行所有操作的前端界麵。

其它的一些工具如 dpkg-deb 和 dpkg-query 等也使用 dpkg 作為執行某些操作的前端。

現在大多數係統管理員使用 Apt、Apt-Get 及 Aptitude 等工具,不用費心就可以輕鬆地管理軟件。

盡管如此,必要的時候還是需要用 dpkg 來安裝某些軟件。其它的一些在 Linux 係統上廣泛使用的包管理工具還有 yumdnfapt-getrpmZypper、pacman、urpmi 等等。

現在,我要在裝有 Ubuntu 15.10 的機器上用一些實例講解最常用的 dpkg 命令。

1) dpkg 常見命令的語法及 dpkg 文件位置

下麵是 dpkg 常見命令的語法及 dpkg 相關文件的位置,如果想深入了解,這些對你肯定大有益處。


  1. ### dpkg 命令的語法
  2. $ dpkg -[command] [.deb package name]
  3. $ dpkg -[command] [package name]
  4. ### dpkg 相關文件的位置
  5. $ /var/lib/dpkg
  6. ### 這個文件包含了被 dpkg 命令(install、remove 等)所修改的包的信息
  7. $ /var/lib/dpkg/status
  8. ### 這個文件包含了可用包的列表
  9. $ /var/lib/dpkg/status

2) 安裝/升級軟件

在基於 Debian 的係統裏,比如 Debian、Mint、Ubuntu 和 elementryOS,用以下命令來安裝/升級 .deb 軟件包。這裏我要用 atom-amd64.deb 文件安裝 Atom。要是已經安裝了 Atom,就會升級它。要麼就會安裝一個新的 Atom。


  1. ### 安裝或升級 dpkg 軟件包
  2. $ sudo dpkg -i atom-amd64.deb
  3. Selecting previously unselected package atom.
  4. (Reading database ... 426102 files and directories currently installed.)
  5. Preparing to unpack atom-amd64.deb ...
  6. Unpacking atom (1.5.3) over (1.5.3) ...
  7. Setting up atom (1.5.3) ...
  8. Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
  9. Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
  10. Rebuilding /usr/share/applications/bamf-2.index...
  11. Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
  12. Processing triggers for mime-support (3.58ubuntu1) ...

3) 從文件夾裏安裝軟件

在基於 Debian 的係統裏,用下列命令從目錄中逐個安裝軟件。這會安裝/opt/software 目錄下的所有以 .deb 為後綴的軟件。


  1. $ sudo dpkg -iR /opt/software
  2. Selecting previously unselected package atom.
  3. (Reading database ... 423303 files and directories currently installed.)
  4. Preparing to unpack /opt/software/atom-amd64.deb ...
  5. Unpacking atom (1.5.3) ...
  6. Setting up atom (1.5.3) ...
  7. Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
  8. Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
  9. Rebuilding /usr/share/applications/bamf-2.index...
  10. Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
  11. Processing triggers for mime-support (3.58ubuntu1) ...

4) 顯示已安裝軟件列表

以下命令可以列出 Debian 係的係統中所有已安裝的軟件,同時會顯示軟件版本和描述信息。


  1. $ dpkg -l
  2. Desired=Unknown/Install/Remove/Purge/Hold
  3. | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
  4. |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
  5. ||/ Name Version Architecture Description
  6. +++-===========================-==================================-============-================================================================
  7. ii account-plugin-aim 3.12.10-0ubuntu2 amd64 Messaging account plugin for AIM
  8. ii account-plugin-facebook 0.12+15.10.20150723-0ubuntu1 all GNOME Control Center account plugin for single signon - facebook
  9. ii account-plugin-flickr 0.12+15.10.20150723-0ubuntu1 all GNOME Control Center account plugin for single signon - flickr
  10. ii account-plugin-google 0.12+15.10.20150723-0ubuntu1 all GNOME Control Center account plugin for single signon
  11. ii account-plugin-jabber 3.12.10-0ubuntu2 amd64 Messaging account plugin for Jabber/XMPP
  12. ii account-plugin-salut 3.12.10-0ubuntu2 amd64 Messaging account plugin for Local XMPP (Salut)
  13. .
  14. .

5) 查看指定的已安裝軟件

用以下命令列出指定的一個已安裝軟件,同時會顯示軟件版本和描述信息。


  1. $ dpkg -l atom
  2. Desired=Unknown/Install/Remove/Purge/Hold
  3. | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
  4. |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
  5. ||/ Name Version Architecture Description
  6. +++-==========-=========-===================-============================================
  7. ii atom 1.5.3 amd64 A hackable text editor for the 21st Century.

6) 查看軟件安裝目錄

以下命令可以在基於 Debian 的係統上查看軟件的安裝路徑。


  1. $ dpkg -L atom
  2. /.
  3. /usr
  4. /usr/bin
  5. /usr/bin/atom
  6. /usr/share
  7. /usr/share/lintian
  8. /usr/share/lintian/overrides
  9. /usr/share/lintian/overrides/atom
  10. /usr/share/pixmaps
  11. /usr/share/pixmaps/atom.png
  12. /usr/share/doc

7) 查看 deb 包內容

下列命令可以查看 deb 包內容。它會顯示 .deb 包中的一係列文件。


  1. $ dpkg -c atom-amd64.deb
  2. drwxr-xr-x root/root 0 2016-02-13 02:13 ./
  3. drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/
  4. drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/bin/
  5. -rwxr-xr-x root/root 3067 2016-02-13 02:13 ./usr/bin/atom
  6. drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/
  7. drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/lintian/
  8. drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/lintian/overrides/
  9. -rw-r--r-- root/root 299 2016-02-13 02:13 ./usr/share/lintian/overrides/atom
  10. drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/pixmaps/
  11. -rw-r--r-- root/root 643183 2016-02-13 02:13 ./usr/share/pixmaps/atom.png
  12. drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/doc/
  13. .
  14. .

8) 顯示軟件的詳細信息

以下命令可以顯示軟件的詳細信息,如軟件名、軟件類別、版本、維護者、軟件架構、依賴的軟件、軟件描述等等。


  1. $ dpkg -s atom
  2. Package: atom
  3. Status: install ok installed
  4. Priority: optional
  5. Section: devel
  6. Installed-Size: 213496
  7. Maintainer: GitHub <atom@github.com>Architecture: amd64
  8. Version: 1.5.3
  9. Depends: git, gconf2, gconf-service, libgtk2.0-0, libudev0 | libudev1, libgcrypt11 | libgcrypt20, libnotify4, libxtst6, libnss3, python, gvfs-bin, xdg-utils, libcap2
  10. Recommends: lsb-release
  11. Suggests: libgnome-keyring0, gir1.2-gnomekeyring-1.0
  12. Description: A hackable text editor for the 21st Century.
  13. Atom is a free and open source text editor that is modern, approachable, and hackable to the core.</atom@github.com>

9) 查看文件屬於哪個軟件

用以下命令來查看文件屬於哪個軟件。


  1. $ dpkg -S /usr/bin/atom
  2. atom: /usr/bin/atom

10) 移除/刪除軟件

以下命令可以用來移除/刪除一個已經安裝的軟件,但不刪除配置文件。


  1. $ sudo dpkg -r atom
  2. (Reading database ... 426404 files and directories currently installed.)
  3. Removing atom (1.5.3) ...
  4. Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
  5. Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
  6. Rebuilding /usr/share/applications/bamf-2.index...
  7. Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
  8. Processing triggers for mime-support (3.58ubuntu1) ...

11) 清除軟件

以下命令可以用來移除/刪除包括配置文件在內的所有文件。


  1. $ sudo dpkg -P atom
  2. (Reading database ... 426404 files and directories currently installed.)
  3. Removing atom (1.5.3) ...
  4. Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
  5. Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
  6. Rebuilding /usr/share/applications/bamf-2.index...
  7. Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
  8. Processing triggers for mime-support (3.58ubuntu1) ...

12) 了解更多

用以下命令來查看更多關於 dpkg 的信息。


  1. $ dpkg -help
  2. $ man dpkg

開始體驗 dpkg 吧。

原文發布時間為:2017-11-12

本文來自雲棲社區合作夥伴“Linux中國”

最後更新:2017-06-02 19:32:54

  上一篇:go  Nature:人工智能研究的盲點
  下一篇:go  動手寫個數字輸入框2:起手式——攔截非法字符