I'd like to be able to output a list of all the dependencies of an installed package, including the version numbers of the dependencies that I have installed.
4 Answers
I normally use rdepends
for that, install it with sudo apt-get install apt-rdepends
or look for in the Ubuntu Software Center.
After installing the program you can use it simply by opening a terminal and typing apt-rdepends <package_name>
.
It will show you all the dependencies any package that is in your apt
lists required to install and all the dependencies of a package that you might be thinking about installing.
It shows the information in a tree diagram where all the dependencies from one package are compared against all the dependencies of the each package dependency... (and so).
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
After that if you want to see if the package is installed in your system simply use this command
dpkg-query -l <package_name>
It will show you if the package is installed, ie
dpkg -l firefox
+++-==============-==============-============================================
ii firefox 8.0+build1-0ub Safe and easy web browser from Mozilla
The ii
in front of the package means that its installed.
-
It looks like this just lists dependencies without telling you whether you have them installed. Is that right?– JayDec 12, 2011 at 20:01
-
Correct, so it also means that you can check if a dependency is installed in your system for a package that you have not yet installed. I have added the method to check the status of a package in your system. Dec 12, 2011 at 21:32
If you need a customized output, it could be a good option to implement a script to accomplish this task using 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)
Example output:
$ 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
-
Thanks jcollado, that's perfect. I noticed that it's a recursive script, grabbing the dependencies of the dependencies as well, but they were sorted in a way that made it easy to isolate only the first-level dependencies. Thanks!– JayDec 12, 2011 at 23:22
use apt-cache
Using firefox as an example :
apt-cache showpkg firefox | less
to quit less type q. I piped it to less as the output can be long. You can pipe it to a file if you wish.
To show your installed packages, use dpkg
dpkg -l
dpkg -l | grep firefox
Updated version of @jcollado'd python script:
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)