How to escape dependency hell?

I have a Ubuntu computer with no internet and a Ubuntu computer with internet. The one without internet requires a driver to be installed through ndiswrapper. The problem is that ndiswrapper-dkms depends on dkms which depends on a few things, and those few things depend on a lot of things, which depend on more, and so on. I've manually downloaded 92 dependencies so far and I'm still needing more. I've been using the code

for i in $(apt-cache depends <package> | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done

which gets the job done but only for one package's dependencies, not the dependencies of the dependencies of the package and so on. This has turned into a multi-hour fight to get all the packages and it's really tedious. I've been running this code to download the .deb files to the USB drive on my online computer, then moving to the offline computer to insert the drive, then running sudo apt install ./* in the folder and hoping for the best. It usually spits out something like this:

...
The following packages have unmet dependencies:
 binutils : Depends: binutils-common (= 2.30-21ubuntu1~18.04.1) but 2.30-21ubuntu1~18.04 is to be installed
            Depends: libbinutils (= 2.30-21ubuntu1~18.04.1) but 2.30-21ubuntu1~18.04 is to be installed
            Depends: binutils-x86-64-linux-gnu (= 2.30-21ubuntu1~18.04.1) but 2.30-21ubuntu1~18.04 is to be installed
 cpp-doc : Depends: cpp-7-doc (>= 7.4.0-1~) but it is not installable
 file : Depends: libmagic1 (= 1:5.32-2ubuntu0.2) but 1:5.32-2ubuntu0.1 is to be installed
 g++-7 : Depends: libstdc++-7-dev (= 7.4.0-1ubuntu1~18.04) but it is not installable
 g++-multilib : Depends: g++-7-multilib (>= 7.4.0-1~) but it is not installable
 gcc-7-multilib : Depends: lib32gcc-7-dev (= 7.4.0-1ubuntu1~18.04) but it is not installable
                  Depends: libx32gcc-7-dev (= 7.4.0-1ubuntu1~18.04) but it is not installable
 gfortran : Depends: gfortran-7 (>= 7.4.0-1~) but it is not installable
 glibc-doc : Depends: glibc-doc-reference (>= 2.18) but it is not installable
 libasan4-dbg : Depends: libasan4 (= 7.4.0-1ubuntu1~18.04) but it is not installable
 libatomic1-dbg : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
                  Depends: libatomic1 (= 8.3.0-6ubuntu1~18.04) but it is not installable
 libbabeltrace1 : Depends: libdw1 (>= 0.126) but it is not installable
 libcc1-0 : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
 libcilkrts5-dbg : Depends: libcilkrts5 (= 7.4.0-1ubuntu1~18.04) but it is not installable
 libfl-dev : Depends: libfl2 (= 2.6.4-6) but it is not installable
 libgcc-7-dev : Depends: libitm1 (>= 7.4.0-1ubuntu1~18.04) but it is not installable
                Depends: libatomic1 (>= 7.4.0-1ubuntu1~18.04) but it is not installable
                Depends: libasan4 (>= 7.4.0-1ubuntu1~18.04) but it is not installable
                Depends: liblsan0 (>= 7.4.0-1ubuntu1~18.04) but it is not installable
                Depends: libtsan0 (>= 7.4.0-1ubuntu1~18.04) but it is not installable
                Depends: libubsan0 (>= 7.4.0-1ubuntu1~18.04) but it is not installable
                Depends: libcilkrts5 (>= 7.4.0-1ubuntu1~18.04) but it is not installable
                Depends: libmpx2 (>= 7.4.0-1ubuntu1~18.04) but it is not installable
 libgcc1 : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
 libgcc1-dbg : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
 libgomp1-dbg : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
                Depends: libgomp1 (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
 libitm1-dbg : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
               Depends: libitm1 (= 8.3.0-6ubuntu1~18.04) but it is not installable
 liblsan0-dbg : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
                Depends: liblsan0 (= 8.3.0-6ubuntu1~18.04) but it is not installable
 libmpx2-dbg : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
               Depends: libmpx2 (= 8.3.0-6ubuntu1~18.04) but it is not installable
 libquadmath0-dbg : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
                    Depends: libquadmath0 (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
 libstdc++6 : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
 libtsan0-dbg : Depends: gcc-8-base (= 8.3.0-6ubuntu1~18.04) but 8.2.0-1ubuntu2~18.04 is to be installed
                Depends: libtsan0 (= 8.3.0-6ubuntu1~18.04) but it is not installable
 libubsan0-dbg : Depends: libubsan0 (= 7.4.0-1ubuntu1~18.04) but it is not installable
 libumfpack5 : Depends: libcholmod3 (>= 1:4.5.2) but it is not going to be installed
 m4 : Depends: libsigsegv2 (>= 2.9) but it is not installable
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

Does anyone know of a method to just dump all the .deb files for a packages dependencies and all subdependencies into a single folder to save my sanity? Thx!


Take a look at apt-offline, a (more) user-friendly way of managing offline dependencies. You'll need to install it first by downloading the debfile and transferring it to your offline machine. You can use something like sudo apt download apt-offline to handle the downloading. Installation can be done using sudo dpkg -i /path/to/your/debfile.deb on the offline machine and just sudo apt install on your online machine.

Once that's done, you'll need to prepare a bunch of things for the actual installation.

  1. Start off by creating a signature of your offline system asking to install the ndiswrapper packages:

    sudo apt-offline set offline.sig --install-packages ndiswrapper-dkms
    
  2. Copy the file to your online machine, and run the following command on the online machine to download all required files:

    apt-offline get offline.sig --bundle ndis-ao.zip
    
  3. Move the zipfile bundle back to your offline machine and run this command on it:

    sudo apt-offline install ndis-ao.zip
    

You should have ndiswrapper-dkms installed at this point and all should be well.


If your apt-offline package fails to install, make note of the dependent packages that failed and resolve them one by one (manually copying as needed). Dependency hell is annoying, but unfortunately that's one of the issues with a more offline system.

You can try taking a look at apt-rdepends as well to generate a complete dependency graph. Combine this with apt download and you might have an alternative solution to the problem, though my testing with this has been inconclusive to say the least.