I need to list/download all the recursive dependencies of a debian package.
Suppose i need to install package a.deb and it depends on package b.deb and again package b.deb depends on package c.deb.
I need to download all the recursive dependent packages so that they can be installed on some other machine without any internet access.
Thanks.
You can use
apt-rdepends
for getting all the dependencies for a package recursively. And by piping the result to grep you can have only the package names and omit unneeded information.Example:
Output:
You can then download those packages using
apt-get download $package
and install them offline on your machine.For some reason
apt-rdepends
did not work for me (when searching the 'docker-engine' package, it missed the dependency ontolibltdl7
which was introduced withdocker-engine 1.11.1-0
).So I came up with following command suite.
Recursively list dependencies
(you obviously have to change
<your-package-here>
at the end of the line with the package you want to analyze)The key here is the
--recurse
option. Unfortunately, you cannot specify the content you want (or I did not find the way) so you need to turn off all unwanted dependencies to keep only "dependencies". It is a bit verbose and hard to remember!From the apt-cache man page:
Download those dependencies
So in order to download those dependencies, run following command which will download them into the current working directory:
Optionally, to install those dependencies
This extends slightly the asked question, but it seems to match the intent of the question.
You need to build the index of the just downloaded packages. This is done from the same folder where all .deb where downloaded:
Then just copy that folder (all .deb + the Packages.gz file) to the target system which does not have Internet access and add the folder to the APT source list.
Et voilà
On a system w/o Internet access, I can install a package (Docker in my example) and its dependencies:
If you only want to download a Debian package, then:
or
Otherwise if you just want a list of a package's dependencies:
Obviously, replace
package
with the package name you want to query for.As midihenry pointed out - install the apt-rdepends package and then run this
this line will get all dependencies recursively and, looking at the second pipe, will download all the packages by name from the stdio, which is what the line -
awk $1 ~ /^Depends:/{print $2}
does. prints out the names of packages. If you run these commands additively, you'll see what i mean.