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.
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.
-
4
-
1@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 3 '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 unix.stackexchange.com/a/362866/23450 – Tino May 3 '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 8:51
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
-
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
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
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.
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. – bac0n Feb 24 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'
– bac0n Feb 24 at 10:15
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
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?
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]
dpkg --get-selections | sed -n 's/[[:space:]]install$//p'
– Tino May 3 '17 at 16:08