How to download all dependencies and packages to directory
I’m trying to install a package on a machine with no Internet connection. What I want to do is download all the packages and dependences on a machine WITH an Internet connection and then sneaker-net everything to the offline computer. I’ve been playing with the apt-get and apt-cache but I haven’t figured out a quick and easy way to download the package and dependencies in one swoop to a directory of my choosing. How would I do this? Am I going about this problem correctly? How would you install offline packages that have a lot of dependencies?
13 Answers 13
The marked answer has the problem that the available packages on the machine that is doing the downloads might be different from the target machine, and thus the package set might be incomplete.
To avoid this and get all dependencies, use the following:
apt-get download $(apt-rdepends |grep -v "^ ")
Some packages returned from apt-rdepends don’t exist with the exact name for apt-get download to download (for example, libc-dev ). In those cases, filter out those exact names (be sure to use ^$ so that other related names, for example libc-dev-bin , that do exist are not skipped).
apt-get download $(apt-rdepends |grep -v "^ " |grep -v "^libc-dev$")
Once downloaded, you can move the .deb files to a machine without Internet and install them:
I used apt-rdepends because it would recursively list the needed packages. However, both solutions have the still (minor IMO) problem that some dependencies can only be provided by packages that are actually named like the dependency. Some dependencies are resolved by packages named differently, but having a corresponding ‘Provides’ tag. For example, I ran into the problem of having a reference on debconf-2.0 unresolved — my kludgy but very workable solution is to manually filter those (usually very few) packages out with another grep -v added to the pipe.
For my above comment above I was confusing «apt-cache rdepends» with apt-rdepends. My mistake — you were correct and this is powerful.
Worked around the error by chaining two grep together. apt-get download $(apt-rdepends
A more general way to prevent the command crashing from a problematic package like libc-dev is to use a for-loop: for PKG in $(apt-rdepends
PACKAGES="wget unzip" apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests \ --no-conflicts --no-breaks --no-replaces --no-enhances \ --no-pre-depends $ | grep "^\w")
This script works great.. downloaded the entire dependency tree. I’m wondering if we could also auto-generate a file having the dpkg commands in proper order, so that the packages with no other dependencies load up first? At present it’s just a brute-force sudo dpkg -i *.deb several times.
@NikhilVJ Once you’ve downloaded your dependencies you can use apt-get install —no-download
Changed your apt-get download line to start like this so that the files are downloaded to the current directory. apt-get download -o Dir::Cache=»./» -o Dir::Cache::archives=»./»
I found that it downloaded both the amd64 and i386 versions for some packages. To download only the version i needed, I extended the grep with in the following way: grep «^\w» | grep -v «i386» (To ignore the i386 ones)
# aptitude clean # aptitude --download-only install # cp /var/cache/apt/archives/*.deb
In real world situations this doesn’t work for you. In most cases many of the dependency packages have been installed, so —download-only won’t download them and won’t put them in /var/cache/apt/archive/ directory. so you end up with incomplete dependency packages.
I guess this will work if you can keep both installations, source (presumably connected to the Internet) and the target (with no Internet connection) exactly the same, for example installing Ubuntu from same ISO on both machines and then cleaning all .deb s on source, then installing desired stuff, copying all newly downloaded .deb s to target machine and then running sudo dpkg -i *.deb .
The aptitude —download-only . approach only works if you have a debian distro with internet connection in your hands.
If you don’t, I think it is better to run the following script on the disconnected debian machine:
apt-get --print-uris --yes install | grep ^\' | cut -d\' -f2 >downloads.list
move the downloads.list file into a connected linux (or non linux) machine, and run:
this downloads all your files into the current directory.After that you can copy them on an USB key and install in your disconnected debian machine.
since (I think) apt version 0.8.11 (ubuntu 11.04) one can use the «download» option for this, so you CAN use it, even if the package is installed already. So use apt-get —print-uris —yes download
This will download all the .debs to the current directory, and will not fail if it can’t find a candidate. This script does not require sudo to run.
nano getdebs.sh && chmod +x getdebs.sh && ./getdebs.sh #!/bin/bash package=ssmtp apt-cache depends "$package" | grep Depends: >> deb.list sed -i -e 's/[<>|:]//g' deb.list sed -i -e 's/Depends//g' deb.list sed -i -e 's/ //g' deb.list filename="deb.list" while read -r line do name="$line" apt-get download "$name" done < "$filename" apt-get download "$package"
I used this as my example because I was actually trying to download the dependencies for ssmtp and it failed on debconf-2.0 , but this script did what I needed.
@aprilian if you find out let me know, but the obvious solution is to fire up Ubuntu 14 and run script 😛
Somewhat simplified (and what worked for me) way that worked for me (based on all the above)
Note that dependencies hierarchy can go deeper then one level
Get dependencies of your package
$ apt-cache depends mongodb | grep Depends: Depends: mongodb-dev Depends: mongodb-server
sudo apt-get --print-uris --yes -d --reinstall install mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-tools | grep "http://" | awk '' | xargs -I'<>' echo <> | tee files.list wget --input-file files.list
Thanks a lot for this. I actually wonder if there is a way to tell APT to also download dependencies and cache them in /var/cache/apt/archives. I wanted to download texlive-full --install-recommends and only ended up with a metapackage called texlive-full in my archives.
its a bit old but I just found out that if the files are in apt cache it won't be downloaded again. "apt-get clean" solved it.
I used apt-cache depends package to get all required packages in any case if the are already installed on system or not. So it will work always correct.
Because the command apt-cache works different, depending on language, you have to try this command on your system and adapt the command. apt-cache depends yourpackage
On an englisch system you get:
$ apt-cache depends yourpackage node Depends: libax25 Depends: libc6
On an german system you get: node
Hängt ab von: libax25 Hängt ab von: libc6
The englisch version with the term:
" Depends: "
You have to change the term " yourpackage " to your wish twice in this command, take care of this!
$ sudo apt-get --print-uris --yes -d --reinstall install yourpackage $(apt-cache depends yourpackage | grep " Depends:" | sed 's/ Depends://' | sed ':a;N;$!ba;s/\n//g') | grep ^\' | cut -d\' -f2 >downloads.list
And the german version with the term:
" Hängt ab von: "
You have to change the term " yourpackage " to your wish twice in this command, take care of this!
This text is used twice in this command, if you want to adapt it to your language take care of this!
$ sudo apt-get --print-uris --yes -d --reinstall install yourpackage $(apt-cache depends yourpackage | grep "Hängt ab von:" | sed 's/ Hängt ab von://' | sed ':a;N;$!ba;s/\n//g') | grep ^\' | cut -d\' -f2 >downloads.list
You get the list of links in downloads.list
Check the list, go to your folder and run the list:
$ cd yourpathToYourFolder $ wget --input-file downloads.list
All your required packages are in:
How to download a software package with all dependencies and sub-dependencies?
Command one only downloads the direct dependencies, like the ones you'd find on packages.ubuntu.com if you were to search kdbg, and command two gives me the error message:
Can't select candidate version for package as it has no candidate
for several different packages.
So, to restate my question, is there a way for me to download kdbg, all of its dependencies, all of those dependencies' dependencies, so on and so forth? Or perhaps I am using one of the above commands incorrectly?
Run apt install
1 Answer 1
You need to run a command that automatically resolves all the .deb file's dependencies and installs the .deb file and its missing dependencies with the same command. You will need a working internet connection (which you have) and your installed software to be updated with sudo apt update && sudo apt upgrade to download any missing dependencies. Open the terminal and type:
apt download package-name apt install --simulate ./package-name.deb # dry run doesn't install anything
where package-name should be replaced by the name of the package that you are trying to download and package-name.deb should be replaced by the name of the .deb file that you are trying to install.
The second command doesn't install anything, it's just a dry run simulation to list the dependencies that need to be installed on the offline machine. You might also have to run the apt install --simulate ./package-name.deb command again in case one or more of the .deb files that you download itself has unmet dependencies.
In case the Ubuntu is not installed on the computer that you are downloading packages from, then you can either boot from the same bootable media that you used to install Ubuntu and download the .deb files from an Ubuntu live session or visit the official Ubuntu Package Search website and download the .deb files manually.