dpkg 删除软件_dpkg 命令教程

本文介绍了dpkg作为Debian系统的主要软件包管理工具,详细讲解了如何使用dpkg安装、列出、删除软件包,包括安装软件、查看已安装包、删除包、查看包内容、软件位置、重新配置等操作,以及dpkg的各种高级用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

dpkg是Debian和基于Debian的系统中的主要软件包管理程序,用于安装,构建,删除和管理软件包。

安装软件包

要安装“ .deb ”软件包,请使用带有“ -i ”选项的命令。例如,要安装名为“ htop_2.2.0-1+b1_amd64.deb ”的“ .deb ”软件包,请使用以下命令。

root@LimeLinux:~# lshtop_2.2.0-1+b1_amd64.debroot@LimeLinux:~# dpkg -i htop_2.2.0-1+b1_amd64.deb Selecting previously unselected package htop.(Reading database ... 27602 files and directories currently installed.)Preparing to unpack htop_2.2.0-1+b1_amd64.deb ...Unpacking htop (2.2.0-1+b1) ...Setting up htop (2.2.0-1+b1) ...Processing triggers for mime-support (3.62) ...Processing triggers for man-db (2.8.5-2) ...root@LimeLinux:~# 

列出所有已安装的软件包

要查看和列出所有已安装的软件包,请在命令中使用“ -l ”选项。

root@LimeLinux:~# dpkg -l

要查看已安装或未安装的特定软件包,请使用选项“ -l ”以及软件包名称。例如,检查是否安装了 htop 软件包。

root@LimeLinux:~# dpkg -l htopDesired=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  htop           2.2.0-1+b1   amd64        interactive processes viewerroot@LimeLinux:~# 

删除安装的软件包

要删除“ .deb ”软件包,必须指定软件包名称“ htop ”,而不是原始名称“ htop_2.2.0-1+b1_amd64.deb ”,“ -r ”选项用于删除/卸载软件包。

root@LimeLinux:~# dpkg -r htop(Reading database ... 27613 files and directories currently installed.)Removing htop (2.2.0-1+b1) ...Processing triggers for man-db (2.8.5-2) ...Processing triggers for mime-support (3.62) ...root@LimeLinux:~# 

使用' p '选项代替' r',将删除软件包以及配置文件。' r '选项将仅删除软件包,而不会删除配置文件。

root@LimeLinux:~# dpkg -P htop(Reading database ... 27613 files and directories currently installed.)Removing htop (2.2.0-1+b1) ...Processing triggers for man-db (2.8.5-2) ...Processing triggers for mime-support (3.62) ...root@LimeLinux:~# 

查看软件包内容

要查看软件包的内容,使用“ -c ”选项,如图所示,该命令将以长列表格式显示“ .deb ”软件包的内容。

root@LimeLinux:~# dpkg -c htop_2.2.0-1+b1_amd64.deb drwxr-xr-x root/root         0 2018-05-15 16:55 ./drwxr-xr-x root/root         0 2018-05-15 16:55 ./usr/drwxr-xr-x root/root         0 2018-05-15 16:55 ./usr/bin/-rwxr-xr-x root/root    185048 2018-05-15 16:55 ./usr/bin/htopdrwxr-xr-x root/root         0 2018-05-15 16:55 ./usr/share/drwxr-xr-x root/root         0 2018-05-15 16:55 ./usr/share/applications/-rw-r--r-- root/root      2461 2018-05-15 16:55 ./usr/share/applications/htop.desktopdrwxr-xr-x root/root         0 2018-05-15 16:55 ./usr/share/doc/drwxr-xr-x root/root         0 2018-05-15 16:55 ./usr/share/doc/htop/-rw-r--r-- root/root        19 2018-04-11 08:13 ./usr/share/doc/htop/AUTHORS-rw-r--r-- root/root      2192 2018-04-11 08:13 ./usr/share/doc/htop/README-rw-r--r-- root/root       212 2018-05-15 16:55 ./usr/share/doc/htop/changelog.Debian.amd64.gz-rw-r--r-- root/root      5762 2018-05-15 16:55 ./usr/share/doc/htop/changelog.Debian.gz-rw-r--r-- root/root      8071 2018-04-11 08:13 ./usr/share/doc/htop/changelog.gz-rw-r--r-- root/root      1276 2018-04-27 02:59 ./usr/share/doc/htop/copyrightdrwxr-xr-x root/root         0 2018-05-15 16:55 ./usr/share/man/drwxr-xr-x root/root         0 2018-05-15 16:55 ./usr/share/man/man1/-rw-r--r-- root/root      4844 2018-05-15 16:55 ./usr/share/man/man1/htop.1.gzdrwxr-xr-x root/root         0 2018-05-15 16:55 ./usr/share/pixmaps/-rw-r--r-- root/root      3657 2018-05-15 16:55 ./usr/share/pixmaps/htop.pngroot@LimeLinux:~# 

查看软件是否安装

在软件包名称中使用“ -s ”选项,将显示是否已安装。

root@LimeLinux:~# dpkg -s htop dpkg-query: package 'htop' is not installed and no information is availableUse dpkg --info (= dpkg-deb --info) to examine archive files.root@LimeLinux:~# dpkg -i htop_2.2.0-1+b1_amd64.deb Selecting previously unselected package htop.(Reading database ... 27602 files and directories currently installed.)Preparing to unpack htop_2.2.0-1+b1_amd64.deb ...Unpacking htop (2.2.0-1+b1) ...Setting up htop (2.2.0-1+b1) ...Processing triggers for mime-support (3.62) ...Processing triggers for man-db (2.8.5-2) ...root@LimeLinux:~# dpkg -s htop Package: htopStatus: install ok installedPriority: optionalSection: utilsInstalled-Size: 225Maintainer: Daniel Lange Architecture: amd64Source: htop (2.2.0-1)Version: 2.2.0-1+b1Depends: libc6 (>= 2.15), libncursesw6 (>= 6), libtinfo6 (>= 6)Suggests: lsof, straceDescription: interactive processes viewer Htop is an ncursed-based process viewer similar to top, but it allows one to scroll the list vertically and horizontally to see all processes and their full command lines. . Tasks related to processes (killing, renicing) can be done without entering their PIDs.Homepage: https://hisham.hm/htop/root@LimeLinux:~# 

查看软件安装位置

从软件包名称查看安装到系统的位置。

root@LimeLinux:~# dpkg -L htop/./usr/usr/bin/usr/bin/htop/usr/share/usr/share/applications/usr/share/applications/htop.desktop/usr/share/doc/usr/share/doc/htop/usr/share/doc/htop/AUTHORS/usr/share/doc/htop/README/usr/share/doc/htop/changelog.Debian.amd64.gz/usr/share/doc/htop/changelog.Debian.gz/usr/share/doc/htop/changelog.gz/usr/share/doc/htop/copyright/usr/share/man/usr/share/man/man1/usr/share/man/man1/htop.1.gz/usr/share/pixmaps/usr/share/pixmaps/htop.pngroot@LimeLinux:~#

从目录安装所有软件

递归地安装在指定目录及其所有子目录中找到的所有匹配模式“ * .deb ”的常规文件。可以将其与“ -R ”和“ –install ”选项一起使用。例如,我将从名为“ debpackages ”的目录中安装所有“ .deb ”软件包。

root@LimeLinux:~# dpkg -R --install nginx /

打开软件包但不配置

使用动作“ –unpack ”将打开软件包的包装,但不会安装或配置。

root@LimeLinux:~# dpkg --unpack htop_2.2.0-1+b1_amd64.deb Selecting previously unselected package htop.(Reading database ... 27602 files and directories currently installed.)Preparing to unpack htop_2.2.0-1+b1_amd64.deb ...Unpacking htop (2.2.0-1+b1) ...Processing triggers for mime-support (3.62) ...Processing triggers for man-db (2.8.5-2) ...root@LimeLinux:~# ls

重新配置解包的软件包

选项“ –configure ”将重新配置已经解压缩的软件包。

root@LimeLinux:~# dpkg --configure htopSetting up htop (2.2.0-1+b1) ...root@LimeLinux:~# 

替换可用包信息

“ –-update-avail ”选项将旧信息替换为Packages文件中的可用信息。

root@LimeLinux:~# dpkg –-update-avail bmon

删除软件包中现有的可用信息

“ -clear-avaial ”操作将删除有关可用软件包的当前信息。

root@LimeLinux:~# dpkg --clear-avail

删除不可用软件包

root@LimeLinux:~# dpkg --forget-old-unavail

获取有关dpkg的所有帮助

“ –help ”选项将显示dpkg命令的可用选项列表。

root@LimeLinux:~# dpkg --helpUsage: dpkg [ ...] Commands:  -i|--install       <.deb file name>... | -R|--recursive ...  --unpack           <.deb file name>... | -R|--recursive ...  -A|--record-avail  <.deb file name>... | -R|--recursive ...  --configure        ... | -a|--pending  --triggers-only    ... | -a|--pending  -r|--remove        ... | -a|--pending  -P|--purge         ... | -a|--pending  -V|--verify [...]       Verify the integrity of package(s).  --get-selections [...]  Get list of selections to stdout.  --set-selections                 Set package selections from stdin.  --clear-selections               Deselect every non-essential package.  --update-avail [] Replace available packages info.  --merge-avail []  Merge with info from file.  --clear-avail                    Erase existing available info.  --forget-old-unavail             Forget uninstalled unavailable pkgs.  -s|--status [...]       Display package status details.  -p|--print-avail [...]  Display available version details.  -L|--listfiles ...      List files 'owned' by package(s).  -l|--list [...]         List packages concisely.  -S|--search ...         Find package(s) owning file(s).  -C|--audit [...]        Check for broken package(s).  --yet-to-unpack                  Print packages selected for installation.  --predep-package                 Print pre-dependencies to unpack.  --add-architecture         Add  to the list of architectures.  --remove-architecture      Remove  from the list of architectures.  --print-architecture             Print dpkg architecture.  --print-foreign-architectures    Print allowed foreign architectures.  --assert-               Assert support for the specified feature.  --validate-      Validate a 's .  --compare-versions    Compare version numbers - see below.  --force-help                     Show help on forcing.  -Dh|--debug=help                 Show help on debugging.  -?, --help                       Show this help message.      --version                    Show the version.Assertable features: support-predepends, working-epoch, long-filenames,  multi-conrep, multi-arch, versioned-provides.Validatable things: pkgname, archname, trigname, version.Use dpkg with -b, --build, -c, --contents, -e, --control, -I, --info,  -f, --field, -x, --extract, -X, --vextract, --ctrl-tarfile, --fsys-tarfileon archives (type dpkg-deb --help).Options:  --admindir=     Use  instead of /var/lib/dpkg.  --root=         Install on a different root directory.  --instdir=      Change installation dir without changing admin dir.  --path-exclude=   Do not install paths which match a shell pattern.  --path-include=   Re-include a pattern after a previous exclusion.  -O|--selected-only         Skip packages not selected for install/upgrade.  -E|--skip-same-version     Skip packages whose same version is installed.  -G|--refuse-downgrade      Skip packages with earlier version than installed.  -B|--auto-deconfigure      Install even if it would break some other package.  --[no-]triggers            Skip or force consequential trigger processing.  --verify-format=   Verify output format (supported: 'rpm').  --no-debsig                Do not try to verify package signatures.  --no-act|--dry-run|--simulate                             Just say what we would do - don't do it.  -D|--debug=         Enable debugging (see -Dhelp or --debug=help).  --status-fd             Send status change updates to file descriptor .  --status-logger=  Send status change updates to 's stdin.  --log=           Log status changes and actions to .  --ignore-depends=,...                             Ignore dependencies involving .  --force-...                Override problems (see --force-help).  --no-force-...|--refuse-...                             Stop when problems encountered.  --abort-after           Abort after encountering  errors.Comparison operators for --compare-versions are:  lt le eq ne ge gt       (treat empty version as earlier than any version);  lt-nl le-nl ge-nl gt-nl (treat empty version as later than any version);  < << <= = >= >> >       (only for compatibility with control file syntax).Use 'apt' or 'aptitude' for user-friendly package management.root@LimeLinux:~# 

----------END----------

5f2d056af56882562435badd4fbfcd71.gif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值