93

How can I check dependency list for a deb package. I am running Ubuntu 11.10 and I have backed up all deb packages from var/cache/apt/archives. I want to format my pc and re-install selected applications only. Also how can I get the list of installed packages and dependencies.

  • For your second question see askubuntu.com/questions/17823/… – htorque Nov 19 '11 at 9:15
  • For the complete list of installed packages use dpkg --get-selections | sed -n 's/[[:space:]]install$//p' – Tino May 3 '17 at 16:08
72

In addition to the dpkg method, you can check the dependencies of packages in the repository:

apt-cache depends package-name

EDIT Updated with @Tino's recommendation. @Tigran's comment no longer applies.

  • 3
    Note: this only works if the package is already installed. – Tigran Saluev Sep 9 '16 at 9:04
  • @TigranSaluev Note that dpkg -I package only works for installed packages. apt-cache works for all packages which are known after you have done apt-get update. – Tino May 3 '17 at 12:07
  • 1
    apt-cache depends package is a better way, in that case, as showpkg does not tell if a dependency is a recommend, conflict etc., so it is a bit puzzling. For a script which does depends combined with showpkg see unix.stackexchange.com/a/362866/23450 – Tino May 3 '17 at 16:08
100

This will show you all the information about the package:

dpkg -I package.deb
  • That no longer works on Ubuntu 14.04: dpkg -I splunkforwarder-6.3.3-f44afce176d0-linux-2.6-amd64.deb new debian package, version 2.0. size 15881308 bytes: control archive=3104 bytes. 153 bytes, 5 lines control 6058 bytes, 207 lines * postinst #!/bin/bash 2912 bytes, 93 lines * preinst #!/bin/bash Package: splunkforwarder Version: 6.3.3 Maintainer: Splunk Inc. <info@splunk.com> Architecture: amd64 Description: Splunk The platform for machine data. – Craig S. Anderson Mar 8 '16 at 22:08
  • @CraigS.Anderson Running 14.04 here and it works just perfect in my case. Should be the accepted answer IMHO. – magic_al Sep 20 '16 at 9:44
  • Don't forget to put /var/cache/apt/archives/ before the package name and use tab completion to find the full package name with version, e.g. dpkg -I /var/cache/apt/archives/elasticsearch_2.4.4_all.deb. – Jason R. Coombs Jan 12 '17 at 16:58
  • 1
    I don't see any dependency information – Nick Jun 21 '17 at 17:45
  • You could add that the package can be obtained without (re)installing it (which is probably a popular use case) with sudo apt-get install --reinstall --download-only [package name]. – Karl Richter Jul 22 '18 at 2:35
2

apt-cache depends [Package-Name] will work as well. Although if you source the .deb package from outside your sources list, things like apt-cache showpkg [Package-Name] && apt-cache depends [Package-Name] might show outdated info or might not sync with the actual installed package hence dpkg -I [Package-Name] would work best in that case.

2

For 14.04 and later:

dpkg doesn't have the -I any more and you have to use dpkg-deb to show package information including dependencies:

dpkg-deb -I package.deb
  • 1
    Hi Fabby, dpkg has no -I option currently. Tested on Ubuntu 12.04 and 16.04. You have to use dpkg-deb instead. – Rup Narayan Apr 28 at 7:36
  • Comment retracted; answer clarified and upvoted – Fabby Apr 28 at 8:17
0

Here is some sloppy, and probably not very encompassing post-processing you can do to dpkg -I output to get dependency items as a list:

Condensed for computers

# dpkg -I package.deb | python -c "import sys, re; t=re.split(r'\n(?= ?[\w]+:)|:', sys.stdin.read()); print '\n'.join([i.strip() for i in {key.strip(): value.strip() for key, value in zip(t[::2], t[1::2])}['Depends'].split(',')])"
#

Expanded for humans:

dpkg -I package.deb | python -c "
    import sys, re;
    # Split keys and values into pairs (zipped together later)
    t=re.split(
        r'\n(?= ?[\w]+:)|:', 
        sys.stdin.read()
    ); 
    # Newline separate each dependency
    print '\n'.join([
        # Trim each dependency value
        i.strip() for i in {
            # Build assoc array from package metadata
            key.strip(): value.strip() 
            for key, value in zip(t[::2], t[1::2])
        }['Depends'].split(',')
    ])
"
  • This will echo the packages which depend on 'foo.deb' and have yet to be installed: dpkg -I foo.deb | for i in $(awk -F', ' '/Depends: /{gsub(/: /, ", "); for (i=2; i<=NF; i++) { gsub(/ .*$/, "", $(i)); printf("%s\n", $(i)); } }'); do dpkg -s $i &> /dev/null || echo $i; done | tr '\n' ' ' – Gregory Burd Sep 17 '15 at 14:48
  • @GregoryBurd, Feel free to edit my answer/psot all you like, I posted it as community wiki for this reason ^u^ – ThorSummoner Sep 17 '15 at 16:35
  • When I run this command on elasticsearch, it emits libc6\nadduser\n Installed-Size\n. That is, it seems to be matching more than just the Depends line. – Jason R. Coombs Jan 12 '17 at 17:01
0

For a specific package version:

apt-cache show <package_name>=<version>

To find available versions: How can I check the available version of a package in the repositories?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.