Linux查看已经安装软件的版本,安装软件的路径,以及dpkg、aptitude、apt-get、apt工具的使用

简介: Linux查看已经安装软件的版本,安装软件的路径,以及dpkg、aptitude、apt-get、apt工具的使用

1 dpkg的使用

1、查看dpkg有哪些命令参数:

dpkg --helpman dpkg

(base) shl@zhihui-mint:~$ dpkg --help
用法:dpkg [<选项> ...] <命令>

命令:
  -i|--install       <.deb 文件名> ... | -R|--recursive <目录> ...
  --unpack           <.deb 文件名> ... | -R|--recursive <目录> ...
  -A|--record-avail  <.deb 文件名> ... | -R|--recursive <目录> ...
  --configure        <软件包名>    ... | -a|--pending
  --triggers-only    <软件包名>    ... | -a|--pending
  -r|--remove        <软件包名>    ... | -a|--pending
  -P|--purge         <软件包名>    ... | -a|--pending
  -V|--verify <软件包名> ...       检查包的完整性。
  --get-selections [<表达式> ...]  把已选中的软件包列表打印到标准输出。
  --set-selections                 从标准输入里读出要选择的软件。
  --clear-selections               取消选中所有不必要的软件包。
  --update-avail <软件包文件>      替换现有可安装的软件包信息。
  --merge-avail  <软件包文件>      把文件中的信息合并到系统中。
  --clear-avail                    清除现有的软件包信息。
  --forget-old-unavail             忘却已被卸载的不可安装的软件包。
  -s|--status      <软件包名> ...  显示指定软件包的详细状态。
  -p|--print-avail <软件包名> ...  显示可供安装的软件版本。
  -L|--listfiles   <软件包名> ...  列出属于指定软件包的文件。
  -l|--list  [<表达式> ...]        简明地列出软件包的状态。
  -S|--search <表达式> ...         搜索含有指定文件的软件包。
  -C|--audit [<表达式> ...]        检查是否有软件包残损。
  --yet-to-unpack                  列出标记为待解压的软件包。
  --predep-package                 列出待解压的预依赖。
  --add-architecture    <体系结构> 添加 <体系结构> 到体系结构列表。
  --remove-architecture <体系结构> 从架构列表中移除 <体系结构>--print-architecture             显示 dpkg 体系结构。
  --print-foreign-architectures    显示已启用的异质体系结构。
  --assert-<特性>                  对指定特性启用断言支持。
  --validate-<属性> <字符串>       验证一个 <属性><字符串>--compare-vesions <a> <关系> <b> 比较版本号 - 见下。
  --force-help                     显示本强制选项的帮助信息。
  -Dh|--debug=help                 显示有关出错调试的帮助信息。

  -?, --help                       显示本帮助信息。
      --version                    显示版本信息。

Assert 特性: support-predepends, working-epoch, long-filenames,
  multi-conrep, multi-arch, versioned-provides.

可验证的属性:pkgname, archname, trigname, version.

调用 dpkg 并带参数 -b, --build, -c, --contents, -e, --control, -I, --info,
  -f, --field, -x, --extract, -X, --vextract, --ctrl-tarfile, --fsys-tarfile
是针对归档文件的。 (输入 dpkg-deb --help 获取帮助)

选项:
  --admindir=<目录>          使用 <目录> 而非 /var/lib/dpkg。
  --root=<目录>              安装到另一个根目录下。
  --instdir=<目录>           改变安装目录的同时保持管理目录不变。
  --path-exclude=<表达式>    不要安装符合Shell表达式的路径。
  --path-include=<表达式>    在排除模式后再包含一个模式。
  -O|--selected-only         忽略没有被选中安装或升级的软件包。
  -E|--skip-same-version     忽略版本与已安装软件版本相同的软件包。
  -G|--refuse-downgrade      忽略版本早于已安装软件版本的的软件包。
  -B|--auto-deconfigure      就算会影响其他软件包,也要安装。
  --[no-]triggers            跳过或强制随之发生的触发器处理。
  --verify-format=<格式>     检查输出格式('rpm'被支持)--no-debsig                不去尝试验证软件包的签名。
  --no-act|--dry-run|--simulate
                             仅报告要执行的操作 - 但是不执行。
  -D|--debug=<八进制数>      开启调试(参见 -Dhelp 或者 --debug=help)--status-fd <n>            发送状态更新到文件描述符<n>--status-logger=<命令>     发送状态更新到 <命令> 的标准输入。
  --log=<文件名>             将状态更新和操作信息到 <文件名>--ignore-depends=<软件包>,...
                             忽略关于 <软件包> 的所有依赖关系。
  --force-...                忽视遇到的问题(参见 --force-help)--no-force-...|--refuse-...
                             当遇到问题时中止运行。
  --abort-after <n>          累计遇到 <n> 个错误后中止。

可供--compare-version 使用的比较运算符有:
 lt le eq ne ge gt        (如果版本号为空,那么就认为它先于任意版本号);
 lt-nl le-nl ge-nl gt-nl  (如果版本号为空,那么就认为它后于任意版本号)< << <= = >= >> >        (仅仅是为了与主控文件的语法兼容)'apt''aptitude' 提供了更为便利的软件包管理。
(base) shl@zhihui-mint:~$

从上面可以看出dpkg的功能还是挺多的,下面举例说明几个:

1) -L|--listfiles <软件包名> ... 列出属于指定软件包的文件。

dpkg -L ros-melodic-ros-tutorials

查看ros-melodic-ros-tutorials软件安装的相关文件目录:

(base) shl@zhihui-mint:~$ dpkg -L vim
/.
/usr
/usr/bin
/usr/bin/vim.basic
/usr/share
/usr/share/bug
/usr/share/bug/vim
/usr/share/bug/vim/presubj
/usr/share/bug/vim/script
/usr/share/doc
/usr/share/doc/vim
/usr/share/doc/vim/NEWS.Debian.gz
/usr/share/doc/vim/changelog.Debian.gz
/usr/share/doc/vim/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/vim
(base) shl@zhihui-mint:~$

which查看的只是可执行文件所在的路径:

(base) shl@zhihui-mint:~$ which vim
/usr/bin/vim
(base) shl@zhihui-mint:~$

2)dpkg --print-architecture查看系统的体系架构

(base) shl@zhihui-mint:~$ dpkg --print-architecture
amd64
(base) shl@zhihui-mint:~$

2 Linux查看已经安装的软件以及版本

2.1 Linux查看已经安装的软件有哪些

1、使用dpkg -l列举出已经安装的所有软件

(base) shl@zhihui-mint:~$ dpkg -l
期望状态=未知(u)/安装(i)/删除(r)/清除(p)/保持(h)
| 状态=未安装(n)/已安装(i)/仅存配置(c)/仅解压缩(U)/配置失败(F)/不完全安装(H)/触发器等待(W)/触发器未决(T)
|/ 错误?=()/须重装(R) (状态,错误:大写=故障)
||/ 名称                                                  版本                            体系结构                        描述
+++-=====================================================-===============================-===============================-================================================================================================================
ii  accountsservice                                       0.6.45-1ubuntu1                 amd64                           query and manipulate user account information
ii  acl                                                   2.2.52-3build1                  amd64                           Access control list utilities
ii  acpi-support                                          0.142                           amd64                           scripts for handling many ACPI events
ii  acpid                                                 1:2.0.28-1ubuntu1               amd64                           Advanced Configuration and Power Interface event daemon
ii  add-apt-key                                           1.0-0.5                         all                             Command line tool to add GPG keys to the APT keyring
ii  adduser                                               3.116ubuntu1                    all                             add and remove users and groups
ii  adium-theme-ubuntu                                    0.3.4-0ubuntu4                  all                             Adium message style for Ubuntu
ii  adwaita-icon-theme                                    3.28.0-1ubuntu1                 all                             default icon theme of GNOME (small subset)
......
ii  zenity                                                3.28.1-1                        amd64                           Display graphical dialog boxes from shell scripts
ii  zenity-common                                         3.28.1-1                        all                             Display graphical dialog boxes from shell scripts (common files)
ii  zip                                                   3.0-11build1                    amd64                           Archiver for .zip files
ii  zlib1g:amd64                                          1:1.2.11.dfsg-0ubuntu2          amd64                           compression library - runtime
ii  zlib1g:i386                                           1:1.2.11.dfsg-0ubuntu2          i386                            compression library - runtime
ii  zlib1g-dev:amd64                                      1:1.2.11.dfsg-0ubuntu2          amd64                           compression library - development
(base) shl@zhihui-mint:~$

2、如果只想查看某个软件是否安装,是需要结合grep过滤搜索一下即可

dpkg -l | grep 软件包名

例如查看vim是否安装

在这里插入图片描述

2.2 查看已经安装软件的版本

2.2.1 使用dpkg -l <软件包名>查看安装软件版本

(base) shl@zhihui-mint:~$ dpkg -l vim
期望状态=未知(u)/安装(i)/删除(r)/清除(p)/保持(h)
| 状态=未安装(n)/已安装(i)/仅存配置(c)/仅解压缩(U)/配置失败(F)/不完全安装(H)/触发器等待(W)/触发器未决(T)
|/ 错误?=()/须重装(R) (状态,错误:大写=故障)
||/ 名称                                                  版本                            体系结构                        描述
+++-=====================================================-===============================-===============================-================================================================================================================
ii  vim                                                   2:8.0.1453-1ubuntu1.3           amd64                           Vi IMproved - enhanced vi editor
(base) shl@zhihui-mint:~$

2.2.2 使用apt-show-versions -a <软件包名>查看安装软件版本

需要先安装apt-show-version工具:

sudo apt install apt-show-versions

(base) shl@zhihui-mint:~$ apt-show-versions vim
vim:amd64/bionic-security 2:8.0.1453-1ubuntu1.3 upgradeable to 2:8.0.1453-1ubuntu1.4
vim:i386 not installed
(base) shl@zhihui-mint:~$ apt-show-versions -a vim
vim:amd64 2:8.0.1453-1ubuntu1.3 install ok installed
vim:amd64 2:8.0.1453-1ubuntu1   bionic          mirrors.aliyun.com
vim:amd64 2:8.0.1453-1ubuntu1   bionic          archive.ubuntu.com
vim:amd64 2:8.0.1453-1ubuntu1.4 bionic-security mirrors.aliyun.com
vim:amd64 2:8.0.1453-1ubuntu1.4 bionic-security security.ubuntu.com
vim:amd64 2:8.0.1453-1ubuntu1.4 bionic-updates  archive.ubuntu.com
vim:amd64 2:8.0.1453-1ubuntu1.4 bionic-updates  mirrors.aliyun.com
No stable version
vim:amd64/bionic-security 2:8.0.1453-1ubuntu1.3 upgradeable to 2:8.0.1453-1ubuntu1.4
vim:i386 2:8.0.1453-1ubuntu1   bionic          archive.ubuntu.com
vim:i386 2:8.0.1453-1ubuntu1   bionic          mirrors.aliyun.com
vim:i386 2:8.0.1453-1ubuntu1.4 bionic-security security.ubuntu.com
vim:i386 2:8.0.1453-1ubuntu1.4 bionic-security mirrors.aliyun.com
vim:i386 2:8.0.1453-1ubuntu1.4 bionic-updates  mirrors.aliyun.com
vim:i386 2:8.0.1453-1ubuntu1.4 bionic-updates  archive.ubuntu.com
No stable version
vim:i386 not installed
(base) shl@zhihui-mint:~$

2.2.3 使用aptitude show <软件包名> 查看安装软件版本

使用aptitude show查看的信息更详细

(base) shl@zhihui-mint:~$ sudo aptitude show vim
Package: vim                             
Version: 2:8.0.1453-1ubuntu1.4
State: installed (2:8.0.1453-1ubuntu1.3), upgrade available (2:8.0.1453-1ubuntu1.4)
Automatically installed: no
Priority: 可选
Section: editors
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Uncompressed Size: 2,856 k
Depends: vim-common (= 2:8.0.1453-1ubuntu1.4), vim-runtime (= 2:8.0.1453-1ubuntu1.4), libacl1 (>= 2.2.51-8), libc6 (>= 2.15), libgpm2 (>= 1.20.7), libpython3.6 (>= 3.6.5), libselinux1 (>= 1.32), libtinfo5 (>= 6)
Suggests: ctags, vim-doc, vim-scripts
Conflicts: vim:i386
Provides: editor
Provided by: vim-athena (2:8.0.1453-1ubuntu1), vim-athena (2:8.0.1453-1ubuntu1.4), vim-gtk (2:8.0.1453-1ubuntu1), vim-gtk (2:8.0.1453-1ubuntu1.4), vim-gtk3 (2:8.0.1453-1ubuntu1), vim-gtk3 (2:8.0.1453-1ubuntu1.4), vim-nox
             (2:8.0.1453-1ubuntu1), vim-nox (2:8.0.1453-1ubuntu1.4)
Description: Vi 增强版 - 增强的 vi 编辑器
 Vim 是一个与 UNIX 编辑器 Vi 几乎完全兼容的版本。 

 Vim 在 vi 的基础上添加了许多特性:多次撤销、语法高亮、命令行 历史、 在线帮助、文件名补全、块操作、折叠、Unicode 支持等。 

 此软件包提供了一个带有一系列标准功能的 vim。它不提供 Vim 的 图形界面,如果您需要更多(或更少)的功能,请查看其它 vim-* 软 件包。
Homepage: https://vim.sourceforge.io/


(base) shl@zhihui-mint:~$

3 Linux查看安装软件包的文件路径

3.1 使用dpkg -L <软件包名> 查看安装软件包的文件路径

(base) shl@zhihui-mint:~$ dpkg -L vim
/.
/usr
/usr/bin
/usr/bin/vim.basic
/usr/share
/usr/share/bug
/usr/share/bug/vim
/usr/share/bug/vim/presubj
/usr/share/bug/vim/script
/usr/share/doc
/usr/share/doc/vim
/usr/share/doc/vim/NEWS.Debian.gz
/usr/share/doc/vim/changelog.Debian.gz
/usr/share/doc/vim/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/vim
(base) shl@zhihui-mint:~$

3.2 使用whereis <软件包名> 查看安装软件包的文件路径

(base) shl@zhihui-mint:~$ whereis vim
vim: /usr/bin/vim.tiny /usr/bin/vim.basic /usr/bin/vim /etc/vim /usr/share/vim /usr/share/man/man1/vim.1.gz
(base) shl@zhihui-mint:~

3.3 使用which <软件包名> 查看可执行文件的路径

(base) shl@zhihui-mint:~$ which vim
/usr/bin/vim
(base) shl@zhihui-mint:~$

4 aptitude工具的使用

使用man aptitude可以查看更多参数选项信息

aptitude也是linux上的一个软件包安装管理工具,使用如下:

(base) shl@zhihui-mint:~$ aptitude -h
aptitude 0.8.10
Usage: aptitude [-S fname] [-u|-i]
       aptitude [options] <action> ...

Actions (if none is specified, aptitude will enter interactive mode):

 install         Install/upgrade packages.
 remove          Remove packages.
 purge           Remove packages and their configuration files.
 hold            Place packages on hold.
 unhold          Cancel a hold command for a package.
 markauto        Mark packages as having been automatically installed.
 unmarkauto      Mark packages as having been manually installed.
 forbid-version  Forbid aptitude from upgrading to a specific package version.
 update          Download lists of new/upgradable packages.
 safe-upgrade    Perform a safe upgrade.
 full-upgrade    Perform an upgrade, possibly installing and removing packages.
 build-dep       Install the build-dependencies of packages.
 forget-new      Forget what packages are "new".
 search          Search for a package by name and/or expression.
 show            Display detailed info about a package.
 showsrc         Display detailed info about a source package (apt wrapper).
 versions        Displays the versions of specified packages.
 clean           Erase downloaded package files.
 autoclean       Erase old downloaded package files.
 changelog       View a package's changelog.
 download        Download the .deb file for a package (apt wrapper).
 source          Download source package (apt wrapper).
 reinstall       Reinstall a currently installed package.
 why             Explain why a particular package should be installed.
 why-not         Explain why a particular package cannot be installed.

 add-user-tag    Add user tag to packages/patterns.
 remove-user-tag Remove user tag from packages/patterns.

Options:
 -h              This help text.
 --no-gui        Do not use the GTK GUI even if available.
 -s              Simulate actions, but do not actually perform them.
 -d              Only download packages, do not install or remove anything.
 -P              Always prompt for confirmation of actions.
 -y              Assume that the answer to simple yes/no questions is 'yes'.
 -F format       Specify a format for displaying search results; see the manual.
 -O order        Specify how search results should be sorted; see the manual.
 -w width        Specify the display width for formatting search results.
 -f              Aggressively try to fix broken packages.
 -V              Show which versions of packages are to be installed.
 -D              Show the dependencies of automatically changed packages.
 -Z              Show the change in installed size of each package.
 -v              Display extra information. (may be supplied multiple times).
 -t [release]    Set the release from which packages should be installed.
 -q              In command-line mode, suppress the incremental progress
                  indicators.
 -o key=val      Directly set the configuration option named 'key'.
 --with(out)-recommends     Specify whether or not to treat recommends as
                            strong dependencies.
 -S fname        Read the aptitude extended status info from fname.
 -u              Download new package lists on startup.
                  (terminal interface only)
 -i              Perform an install run on startup.
                  (terminal interface only)

See the manual page for a complete list and description of all the options.

This aptitude does not have Super Cow Powers.
(base) shl@zhihui-mint:~$

5 apt工具的使用

使用man apt可以查看更多参数选项信息

(base) shl@zhihui-mint:~$ apt -h
apt
Usage: apt command [options]
       apt help command [options]

Commands:
  add-repository   - Add entries to apt sources.list
  autoclean        - Erase old downloaded archive files
  autoremove       - Remove automatically all unused packages
  build            - Build binary or source packages from sources
  build-dep        - Configure build-dependencies for source packages
  changelog        - View a package's changelog
  check            - Verify that there are no broken dependencies
  clean            - Erase downloaded archive files
  contains         - List packages containing a file
  content          - List files contained in a package
  deb              - Install a .deb package
  depends          - Show raw dependency information for a package
  dist-upgrade     - Upgrade the system by removing/installing/upgrading packages
  download         - Download the .deb file for a package
  edit-sources     - Edit /etc/apt/sources.list with your preferred text editor
  dselect-upgrade  - Follow dselect selections
  full-upgrade     - Same as 'dist-upgrade'
  held             - List all held packages
  help             - Show help for a command
  hold             - Hold a package
  install          - Install/upgrade packages
  list             - List packages based on package names
  policy           - Show policy settings
  purge            - Remove packages and their configuration files
  recommends       - List missing recommended packages for a particular package
  rdepends         - Show reverse dependency information for a package
  reinstall        - Download and (possibly) reinstall a currently installed package
  remove           - Remove packages
  search           - Search for a package by name and/or expression
  show             - Display detailed information about a package
  showhold         - Same as 'held'
  showsrc          - Display all the source package records that match the given package name
  source           - Download source archives
  sources          - Same as 'edit-sources'
  unhold           - Unhold a package
  update           - Download lists of new/upgradable packages
  upgrade          - Perform a safe upgrade
  version          - Show the installed version of a package

(base) shl@zhihui-mint:~$

6 apt-get工具的使用

使用man apt-get可以查看更多参数选项信息

(base) shl@zhihui-mint:~$ apt-get -h
apt 1.6.12ubuntu0.1 (amd64)
用法: apt-get [选项] 命令
    apt-get [选项] install|remove 软件包1 [软件包2 ...]
    apt-get [选项] source 软件包1 [软件包2 ...]

apt-get 可以从认证软件源下载软件包及相关信息,以便安装和升级软件包,
或者用于移除软件包。在这些过程中,软件包依赖会被妥善处理。

常用命令:
  update - 取回更新的软件包列表信息
  upgrade - 进行一次升级
  install - 安装新的软件包(注:软件包名称是 libc6 而非 libc6.deb)
  remove - 卸载软件包
  purge - 卸载并清除软件包的配置
  autoremove - 卸载所有自动安装且不再使用的软件包
  dist-upgrade - 发行版升级,见 apt-get(8)
  dselect-upgrade - 根据 dselect 的选择来进行升级
  build-dep - 为源码包配置所需的编译依赖关系
  clean - 删除所有已下载的包文件
  autoclean - 删除已下载的旧包文件
  check - 核对以确认系统的依赖关系的完整性
  source - 下载源码包文件
  download - 下载指定的二进制包到当前目录
  changelog - 下载指定软件包,并显示其变更日志(changelog)

参见 apt-get(8) 以获取更多关于可用命令的信息。
程序配置选项及语法都已经在 apt.conf(5) 中阐明。
欲知如何配置软件源,请参阅 sources.list(5)。
软件包及其版本偏好可以通过 apt_preferences(5) 来设置。
关于安全方面的细节可以参考 apt-secure(8).
                                         本 APT 具有超级牛力。
(base) shl@zhihui-mint:~$
目录
相关文章
|
16天前
|
Ubuntu Linux
查看Linux系统架构的命令,查看linux系统是哪种架构:AMD、ARM、x86、x86_64、pcc 或 查看Ubuntu的版本号
查看Linux系统架构的命令,查看linux系统是哪种架构:AMD、ARM、x86、x86_64、pcc 或 查看Ubuntu的版本号
130 3
|
12天前
|
监控 安全 Linux
如何利用Kali Linux进行网站渗透测试:最常用工具详解
如何利用Kali Linux进行网站渗透测试:最常用工具详解
45 6
|
12天前
|
安全 Linux API
关于Linux稳定版本的一切你想知道的内容 【ChatGPT】
关于Linux稳定版本的一切你想知道的内容 【ChatGPT】
|
12天前
|
安全 Linux 测试技术
Kali Linux预装的自动化渗透测试工具
Kali Linux预装的自动化渗透测试工具
24 2
|
13天前
|
Linux 编译器 C语言
Linux内核对GCC版本的检测
Linux内核对GCC版本的检测
|
16天前
|
存储 缓存 监控
Linux性能分析工具-perf并生成火焰图
Linux性能分析工具-perf并生成火焰图
|
16天前
|
Linux TensorFlow 算法框架/工具
在Linux上安装其他版本的cmake 或 升级cmake
在Linux上安装其他版本的cmake 或 升级cmake
26 2
|
13天前
|
Ubuntu Linux
用crash工具学习Linux内核 —— 查看cgroup_roots
用crash工具学习Linux内核 —— 查看cgroup_roots
|
4月前
|
Java Linux Shell
Linux探秘之旅:透彻理解路径、命令与系统概念
Linux探秘之旅:透彻理解路径、命令与系统概念
73 1
|
4月前
|
Linux Shell
Linux中认识路径的概念
Linux中认识路径的概念
28 0