Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list/download the recursive dependencies of a debian package?

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.

like image 972
Bharat Bhansali Avatar asked Feb 25 '14 08:02

Bharat Bhansali


People also ask

How do I list the contents of a Debian package?

On Debian/Ubuntu distributions, you can use the dpkg command with the -L flag to list files installed to your Debian system or its derivatives, from a given .

How do I download dependency?

You can use the Maven Dependency Plugin to download dependencies. Run mvn dependency:copy-dependencies , to download all your dependencies and save them in the target/dependency folder. You can change the target location by setting the property outputDirectory .


2 Answers

For some reason apt-rdepends did not work for me (when searching the 'docker-engine' package, it missed the dependency onto libltdl7 which was introduced with docker-engine 1.11.1-0). UPD Supposedly owing to the fact that apt-rdepends doesn't follow and doesn't list Recommends by default. And doesn't follow virtual packages.

So I came up with following command suite.

Recursively list dependencies

$ apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances <your-package-here> | grep "^\w" | sort -u 

(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:

Per default the depends and rdepends print all dependencies

Download those dependencies

So in order to download those dependencies, run following command which will download them into the current working directory:

$ apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances <your-package-here> | grep "^\w" | sort -u) 

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:

$ dpkg-scanpackages . | gzip -9c > Packages.gz 

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.

$ echo "deb file:<your folder here> ./" | sudo tee -a /etc/apt/sources.list $ sudo apt-get update 

Et voilà

On a system w/o Internet access, I can install a package (Docker in my example) and its dependencies:

$ sudo apt-get install docker-engine 
like image 198
Yann Vo Avatar answered Sep 20 '22 01:09

Yann Vo


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:

 $ apt-rdepends cowsay | grep -E '^[a-zA-Z0-9]' 

Output:

cowsay perl libbz2-1.0 libc6 libgcc1 gcc-4.9-base multiarch-support libdb5.3 libgdbm3 dpkg liblzma5 libselinux1 libpcre3 tar libacl1 libattr1 zlib1g install-info perl-base perl-modules 

You can then download those packages using apt-get download $package and install them offline on your machine.

By default, apt installs Recommends, so you might want to run apt-rdepends like so:

apt-rdepends -f Depends,PreDepends,Recommends -s Depends,PreDepends,Recommends cowsay 

Since apt-rdepends by default follows and shows only Depends, PreDepends.

like image 26
Mehdi Yedes Avatar answered Sep 21 '22 01:09

Mehdi Yedes