Shell – Check if multiple dependencies exist before installing a package in Debian or Ubuntu

debiandependenciespackage-managementshell-scriptUbuntu

I already know that I can check if multiple dependencies required to install a package in Debian or Ubuntu exist in my repositories by running the following command:

apt policy first-package second-package ... last-package  

This command also tells me if I have each package currently installed or not.

My question is how to quickly check if multiple dependency packages exist in a supported version of Debian or Ubuntu that I do not currently have installed. Because I do not have that OS currently installed I can't check if the dependency packages exist locally and offline, but I want to check if the required dependency packages exist in the default repositories from the terminal.

One possible use for this information is to check if an application that is installed in Ubuntu can also be installed in the latest version of Ubuntu before installing the latest version of Ubuntu or upgrading the existing OS to the latest version.

Best Answer

The ideal tool for this is rmadison, which is a simple Perl script with few dependencies (the URI module and wget or curl), so it can run pretty much everywhere. It interrogates the Madison services hosted by Debian and Ubuntu to determine the availability of packages:

rmadison gcc-7

tells you which versions of GCC 7 are available in the various Debian suites,

rmadison -u ubuntu gcc-7

does the same for Ubuntu.

You can restrict the output to a specific version:

rmadison -u ubuntu -s bionic gcc-7
Related Question