18

For all answers i found about this topic, the solution was to create, in a certain computer A where i need to install the package, a file containing all dependencies it needs and then downloading it in another computer, let's call it B.

The thing is, i want to have a storage of certain critical software i need to work to be able to install them offline later on in case i have to format my desktop.

I REALLY DON'T CARE about having a lot of redundant .deb files in my computer, and I REALLY DON'T CARE if i'm going to store 1gb of files to install a 10mb software.

So, i want to have any possible dependency downloaded. Is there someway i can do this?

1

4 Answers 4

30

I would go with this:

apt-cache depends -i PACKAGE | awk '/Depends:/ {print $2}' | xargs apt-get download && apt-get download PACKAGE

Then you can install it with dpkg -i *.deb in the directory you downloaded these.

6
  • 1
    I think it did the work, thank you very much. I will just test it a little more times before i come back to thank you again :)
    – ebernardes
    Feb 11, 2015 at 18:06
  • Can you explain me what the awk and xargs commands do? I'm just starting to use linux and i've never seen these 2 commands before
    – ebernardes
    Feb 11, 2015 at 19:03
  • apt-cache depends -i will check for important dependencies for PACKAGE. It will be executed only if apt-get download PACKAGE will succeed in finding PACKAGE out of the ppa repositories that you have added to /etc/apt/sources.list . Now, apt-cache depends -i PACKAGE has output of form Depends: dependency-name. We only need names of dependencies, so that's what awk is doing - it's getting only the second string. For example, try doing apt-cache depends -i vim | awk '{print $2}' . Note also,the whole line to the right of && can be considered one statement Feb 11, 2015 at 21:23
  • 1
    Thanks! But i did some research, and i used the command sed '/^</d' to delete some of the output of apt-cache depends, it was already good, but now it works in every case i'm trying. Thanks a lot!
    – ebernardes
    Feb 13, 2015 at 11:02
  • 1
    it only downloaded the immediate dependencies, didn't get their dependencies and so on. They may already be present on my system, but I need the package with all of its dependencies for installing in another system that does not have internet access.
    – Nikhil VJ
    Mar 24, 2018 at 3:16
2

Is this a one-time thing, or something you want to keep updated? Are you mostly working online, and just want a local backup of all your packages, just in case?

There are several services that you can install that act as an APT proxy/cache. You point APT at your local cache, it will download from the Internet, and keep a locally cached copy of all the packages. This can be very useful if you have lots of computers on your network with an identical selection of packages.

My prefered apt cache is approx, but there is also apt-cacher-ng, and a few others. Each has minor differences about how caching can be configured.

I always use the minimal netinst installers to build my Debian based systems, which means my apt cache usually has almost all the packages to fully build my systems.

1
  • This is something i want to keep just in case, if i need to quickly install some software, even if it's an outdated version, before i can update it later. I will check that, thanks :)
    – ebernardes
    Feb 11, 2015 at 18:52
0

run following python programm:

import subprocess
package=input("insert package name:")
t=subprocess.run(["apt-cache", "depends", "-i", package], stdout=subprocess.PIPE)
if t.stderr or t.returncode:
    print(t.stdout)
    exit(t.stderr)
#print(":", t.stdout)
needed_pacages=t.stdout.split(b"Depends: ")
print(package, "depends of", needed_pacages)
for choices in needed_pacages:
    one_choice_made=False
    for needed_package in choices.split(b"\n"):
        needed_package=needed_package.strip(b"\n ")
        t=subprocess.run(["apt-get", "download", needed_package])
        if t.stderr or t.returncode:
            print("ERROR: Status: {p.returncode}, stdout: {p.stdout}, stderr: {p.stderr}".format(p=t), "package name:", needed_package)
        else:
            one_choice_made = True
            #print("downloaded",vajalik_pakk)
            break
    if not one_choice_made:
        print("could not get one of dependecies", choices)
1
  • 1
    And why is this better than the accepted answer?
    – RalfFriedl
    Apr 17, 2019 at 20:21
0

run following python3 program:

import subprocess
olemas_olevad_pakid=set()
def r(pakk):
    t=subprocess.run(["apt-get", "download", pakk])
    if t.stderr or t.returncode:
        #print("could not load package: Status: {p.returncode}, stdout: {p.stdout}, stderr: {p.stderr}".format(p=t), "paki nimi:", pakk)
        return False
    olemas_olevad_pakid.add(pakk)
    t=subprocess.run(["apt-cache", "depends", "-i", pakk], stdout=subprocess.PIPE)
    if t.stderr or t.returncode:
        print(t.stdout)
        exit(t.stderr)
    #print(":", t.stdout)
    needed_pacages=t.stdout.split(b"Depends: ")[1:]
    #print(pakk, "needs packages:", needed_pacages)
    for choices in needed_pacages:
        one_choice_made=False
        for needed_package in choices.split(b"\n"):
            needed_package=needed_package.strip(b"\n ")
            if needed_package in olemas_olevad_pakid or r(needed_package):
                one_choice_made=True
                break
        if not one_choice_made:
            print("PROBLEM: could not download any of", choices)
            return False
    return True
#for pakk in packages_to_download:
#    print("pakk:",pakk)
#    r(pakk)
r(input("package name:"))

It will download all dependecies of all dependecies not only immediate dependencies. But installing them with dpkg -i *.deb failed. Maybe because apt-cache depends -i package gives misinformation or some some.deb files still need internet connection to install.

1
  • It may fail because dpkg isn't installing the packages in the right order. You might want to retry dpkg a few times until all dependencies are installed.
    – Kateba
    May 23, 2019 at 20:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .