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.

- 5,941
- 7
- 36
- 58

- 5,566
8 Answers
This will show you all the information about the package:
dpkg -I package.deb

- 64,798
-
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
-
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]
. – Kalle Richter Jul 22 '18 at 02: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 '19 at 22:16
-
2
-
FWIW,
-I
stands for--info
. http://manpages.ubuntu.com/manpages/trusty/man1/dpkg.1.html – leoly Dec 06 '21 at 03:59
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 whoapt-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
-
4
-
2@TigranSaluev Note that
dpkg -I package
only works for installed packages.apt-cache
works for all packages which are known after you have doneapt-get update
. – Tino May 03 '17 at 12:07 -
1
apt-cache depends package
is a better way, in that case, asshowpkg
does not tell if a dependency is a recommend, conflict etc., so it is a bit puzzling. For a script which doesdepends
combined withshowpkg
see https://unix.stackexchange.com/a/362866/23450 – Tino May 03 '17 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 caseapt-cache depends package-name=VERSION
seems to be the only option. – Will S Sep 18 '20 at 08:51 -
dpkg -I package worked for deb file just copied from another computer (actually after apt failed to install it). – Martian2020 Sep 26 '21 at 13:35
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

- 99
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
-
Nice set of commands you might want to split
\
those long ones for readability, but leave it up to you. – Feb 24 '21 at 07: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'
– Feb 24 '21 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 getlibc6
,libcurl
,zlib1g
. If Iapt depends libc6
I getlibgcc-s1
andlibcyrpt1
. But if I use your scripts those 2nd levels are not appearing. (Ubuntu 20.04) – gman Mar 19 '21 at 06:04 -
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.

- 31
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?

- 146
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]

- 1,340
- 1
- 11
- 23
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,222
- 3
- 22
- 31
-
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
dpkg --get-selections | sed -n 's/[[:space:]]install$//p'
– Tino May 03 '17 at 16:08