155

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.

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

8 Answers 8

148

This will show you all the information about the package:

dpkg -I package.deb
6
  • 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. Jan 12, 2017 at 16:58
  • 1
    I don't see any dependency information
    – Nick
    Jun 21, 2017 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]. Jul 22, 2018 at 2:35
  • Note that this (or dpkg-deb as reported elsewhere) will only list the package's self-reported dependencies. It does not guarantee that if you install everything listed as a dependency, that you will have everything needed to make the package functional. Packages (especially 3rd party ones) typically assume some level of base system components not listed in their dependencies.
    – user46053
    Jun 28, 2019 at 22:16
  • 2
    This works perfectly on my Ubuntu 19.04.
    – Étienne
    Nov 28, 2019 at 12:59
142

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.


depends VS rdepends

  • apt-cache depends package-name
    //show package-name depends on who

  • apt-cache rdepends package-name
    //show who depends on package-name

depends

$ apt-cache depends vim-runtime
vim-runtime
  Breaks: vim-tiny
 |Recommends: vim
    vim-athena
    vim-gtk
    vim-gtk3
    vim-nox
 |Recommends: vim-gtk
 |Recommends: vim-gtk3
 |Recommends: vim-athena
 |Recommends: vim-nox
  Recommends: vim-tiny
  Enhances: vim-tiny

rdepends

$ apt-cache rdepends vim-runtime
vim-runtime
Reverse Depends:
  vim
  vim
  vim-nox
  vim-gtk
  vim-athena
  vim-gtk3
  vim
  vim-nox
  vim-gtk
  vim-athena
  vim-gtk3
5
  • 4
    Note: this only works if the package is already installed. Sep 9, 2016 at 9:04
  • 2
    @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, 2017 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, 2017 at 16:08
  • apt-cache depends operates on only the candidate package from your sources, not the specific package version you have installed. Can be confusing if your apt repo supports multiple versions. In which case apt-cache depends package-name=VERSION seems to be the only option.
    – Will S
    Sep 18, 2020 at 8:51
  • dpkg -I package worked for deb file just copied from another computer (actually after apt failed to install it). Sep 26, 2021 at 13:35
9

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
2
  • 2
    On Ubuntu 19.04, my dpkg does have an option "-I" (version 1.19.6).
    – Étienne
    Nov 28, 2019 at 13:01
  • My dpkg (v1.21.1) on Ubuntu Jammy 22.04 has -I Sep 27, 2022 at 8:33
4

I know this question is very old, but it is possible. I also had to dig through StackOverflow/AskUbuntu for ALL of this.

This ONLY SHOWS what depends are in the first package. Not all.

There might be some duplicates in the script methods but you can probably filter them out by doing this:

COMMAND | tr " " "\n" | sort | uniq -d | xargs 

Here are the methods:

In a script

dpkg-deb -I <The .deb> | grep -E "Depends|Recommends|Suggests|Pre\-Depends" | tr -d "|," | sed "s/([^)]*)/()/g" | tr -d "()" | tr " " "\n" | grep -Ev "Depends|Recommends|Suggests|Pre\-Depends" | xargs

In a script, but not downloaded (remote)

apt-cache show <The package name> | grep -E "Depends|Recommends|Suggests|Pre\-Depends" | tr -d "|," | sed "s/([^)]*)/()/g" | tr -d "()" | tr " " "\n" | grep -Ev "Depends|Recommends|Suggests|Pre\-Depends" | xargs

Human readable

dpkg-deb -I <The .deb> | grep -E --color=none "Depends|Recommends|Suggests|Pre\-Depends"

Human readable (remote)

apt-cache show <The package name> | grep -E --color=none "Depends|Recommends|Suggests|Pre\-Depends"

Get amount of dependencies

dpkg-deb -I <The .deb> | grep -E "Depends|Recommends|Suggests|Pre\-Depends" | tr -d "|," | sed "s/([^)]*)/()/g" | tr -d "()" | tr " " "\n" | grep -Ev "Depends|Recommends|Suggests|Pre\-Depends" | xargs | tr " " "\n" | wc -l

Get amount of dependencies (remote)

apt-cache show <The package name> | grep -E "Depends|Recommends|Suggests|Pre\-Depends" | tr -d "|," | sed "s/([^)]*)/()/g" | tr -d "()" | tr " " "\n" | grep -Ev "Depends|Recommends|Suggests|Pre\-Depends" | xargs | tr " " "\n" | wc -l
4
  • Nice set of commands you might want to split \ those long ones for readability, but leave it up to you.
    – user986805
    Feb 24, 2021 at 7:00
  • using dpkg-deb --showformat will shorten the command considerably, e.g., dpkg-deb --show --showformat='${Depends} ${Recommends} ${Suggests} ${Pre-Depends}\n' bash_5.1-2_amd64.deb | sed -r 's/ \([^()]*\),?//g'
    – user986805
    Feb 24, 2021 at 10:15
  • this doesn't seem like it works or else I don't understand what i'm looking at. If I apt depends curl I get libc6, libcurl, zlib1g. If I apt depends libc6 I get libgcc-s1 and libcyrpt1. But if I use your scripts those 2nd levels are not appearing. (Ubuntu 20.04)
    – gman
    Mar 19, 2021 at 6:04
  • @gman It worked on Xubuntu 20.04.2 LTS Mar 19, 2021 at 19:08
3

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.

1

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?

1

In case you have the uninstalled package (usually downloaded manually from outside a repository), you need to use dpkg. The following command will show a summary of the package informations, including it's dependencies:

dpkg --info [package name]

In case the package is already installed on your machine (originated from the repository or from a manual download), or is not installed but is available in the repository, you can use apt. The following command will show only the list of it's dependencies.

apt depends [package name]
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(',')
    ])
"
3
  • 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' ' ' Sep 17, 2015 at 14:48
  • @GregoryBurd, Feel free to edit my answer/psot all you like, I posted it as community wiki for this reason ^u^ Sep 17, 2015 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. Jan 12, 2017 at 17:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .