有没有办法查看包中所有依赖项的安装版本?

有没有办法查看包中所有依赖项的安装版本?

我希望能够输出已安装软件包的所有依赖项的列表,包括我已安装的依赖项的版本号。

答案1

我通常使用rdepends它来安装它sudo apt-get install apt-rdepends或在 Ubuntu 软件中心中查找它。

安装该程序后,您只需打开终端并输入即可使用它apt-rdepends <package_name>

它将显示apt列表中任何需要安装的软件包的所有依赖项以及您可能正在考虑安装的软件包的所有依赖项。

它以树状图的形式显示信息,其中一个包的所有依赖项与每个包依赖项的所有依赖项进行比较......(等等)。

IE:

$ apt-rdepends sqlite

Reading package lists... Done
Building dependency tree       
Reading state information... Done
sqlite3
  Depends: libc6 (>= 2.4)
  Depends: libreadline6 (>= 6.0)
  Depends: libsqlite3-0 (>= 3.6.18)
libc6
  Depends: libc-bin (= 2.13-20ubuntu5)
  Depends: libgcc1
  Depends: tzdata
libc-bin
libgcc1
  Depends: gcc-4.6-base (= 4.6.1-9ubuntu3)
  Depends: libc6 (>= 2.2.4)
  PreDepends: multiarch-support
gcc-4.6-base
multiarch-support
  Depends: libc6 (>= 2.13-0ubuntu6)
tzdata
  Depends: debconf (>= 0.5)
  Depends: debconf-2.0
debconf
  PreDepends: perl-base (>= 5.6.1-4)
perl-base
  PreDepends: dpkg (>= 1.14.20)
  PreDepends: libc6 (>= 2.11)
dpkg
  PreDepends: coreutils (>= 5.93-1)
  PreDepends: libbz2-1.0
  PreDepends: libc6 (>= 2.11)
  PreDepends: libselinux1 (>= 1.32)
  PreDepends: xz-utils
  PreDepends: zlib1g (>= 1:1.1.4)
coreutils
  PreDepends: libacl1 (>= 2.2.11-1)
  PreDepends: libattr1 (>= 2.4.41-1)
  PreDepends: libc6 (>= 2.7)
  PreDepends: libselinux1 (>= 1.32)
libacl1
  Depends: libattr1 (>= 2.4.41-1)
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support
libattr1
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support
libselinux1
  Depends: libc6 (>= 2.8)
  PreDepends: multiarch-support
libbz2-1.0
  Depends: libc6 (>= 2.4)
xz-utils
  Depends: libc6 (>= 2.7)
  Depends: liblzma2 (>= 5.0.0)
liblzma2
  Depends: libc6 (>= 2.4)
zlib1g
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support
debconf-2.0
libreadline6
  Depends: libc6 (>= 2.11)
  Depends: libtinfo5 (>= 5.6+20070908)
  Depends: readline-common
libtinfo5
  Depends: libc6 (>= 2.4)
readline-common
  Depends: dpkg (>= 1.15.4)
  Depends: install-info
install-info
  Depends: libc6 (>= 2.4)
libsqlite3-0
  Depends: libc6 (>= 2.4)
  PreDepends: multiarch-support

之后,如果你想查看该软件包是否已安装在你的系统中,只需使用此命令

dpkg-query -l <package_name>

它将显示该包是否已安装,即

dpkg-l 火狐

+++-==============-==============-============================================
ii  firefox        8.0+build1-0ub Safe and easy web browser from Mozilla

ii包前面的 表示已安装。

答案2

如果您需要定制输出,那么使用以下脚本来完成此任务可能是一个不错的选择:python-apt

import argparse
from itertools import chain
from collections import deque
import apt

def main(args):
    packages_seen = set()
    dependencies = deque()

    def print_package(package):
        print package.name, package.installedVersion
        packages_seen.add(package.name)

        or_dependencies = [dependency.or_dependencies
                           for dependency in package.installedDependencies]
        dependencies.extend(chain.from_iterable(or_dependencies))

    cache = apt.cache.Cache()
    package = cache[args.package_name]
    print_package(package)

    while dependencies:
        dependency = dependencies.popleft()
        package_name = dependency.name

        # Skip virtual packages                                                                                                          
        if package_name not in cache:
            continue

        if package_name not in packages_seen:
            package = cache[dependency.name]
            print_package(package)


if __name__ == '__main__':
    parser = argparse.ArgumentParser('Print all package dependencies '
                                     'and their installed version')
    parser.add_argument('package_name', help='Package name')
    args = parser.parse_args()

    main(args)

示例输出:

$ python depends.py sqlite
sqlite 2.8.17-6.1ubuntu1
libc6 2.13-20ubuntu5
libreadline6 6.2-2ubuntu1
libsqlite0 2.8.17-6.1ubuntu1
libc-bin 2.13-20ubuntu5
libgcc1 1:4.6.1-9ubuntu3
tzdata 2011n-0ubuntu0.11.10
readline-common 6.2-2ubuntu1
libtinfo5 5.9-1ubuntu5
multiarch-support 2.13-20ubuntu5
gcc-4.6-base 4.6.1-9ubuntu3
debconf 1.5.40ubuntu1
dpkg 1.16.0.3ubuntu5
install-info 4.13a.dfsg.1-8ubuntu1
perl-base 5.12.4-4
libbz2-1.0 1.0.5-6ubuntu1
libselinux1 2.0.98-1.1
zlib1g 1:1.2.3.4.dfsg-3ubuntu3
coreutils 8.5-1ubuntu6
xz-utils 5.0.0-2
libacl1 2.2.51-3
libattr1 1:2.4.46-3
liblzma2 5.0.0-2

答案3

使用apt-cache

以 Firefox 为例:

apt-cache showpkg firefox | less

要退出 less,请输入 q。我将其通过管道传输到 less,因为输出可能很长。如果您愿意,也可以将其通过管道传输到文件。

要显示已安装的软件包,请使用dpkg

dpkg -l
dpkg -l | grep firefox

答案4

@jcollado 的 Python 脚本的更新版本:

import argparse
from itertools import chain
from collections import deque
import apt

def main(args):
    packages_seen = set()
    dependencies = deque()

    def print_package(package):
        installed_version = package.installed
        print package.name, installed_version
        packages_seen.add(package.name)

        if installed_version:
            or_dependencies = [dependency.or_dependencies
                               for dependency in package.versions[installed_version].dependencies]
            dependencies.extend(chain.from_iterable(or_dependencies))

    cache = apt.cache.Cache()
    package = cache[args.package_name]
    print_package(package)

    while dependencies:
        dependency = dependencies.popleft()
        package_name = dependency.name

        # Skip virtual packages
        if package_name not in cache:
            continue

        if package_name not in packages_seen:
            package = cache[dependency.name]
            print_package(package)


if __name__ == '__main__':
    parser = argparse.ArgumentParser('Print all package dependencies '
                                     'and their installed version')
    parser.add_argument('package_name', help='Package name')
    args = parser.parse_args()

    main(args)

相关内容