How do I use the command line interface (not a GUI) to convert the list of dependency packages in the output from apt-cache depends
into a space‐separated list for use with apt-get download
? Preferably, I’d like the two actions to be executable via a single command.
(By “list of dependency packages”, I’m referring to all packages prefixed by the string “Depends:
”.)
The use case is to download all dependent packages of a package onto a machine with Internet access for use on a machine without Internet access as well as to teach myself how to reformat text via the command line.
One example with a long list of dependencies involves the command apt-cache depends gimp
, the output of which is shown below. (This example includes a few dependencies listed multiple times, but apt-get download
apparently ignores duplicate entries, so there’s no need to filter them out.)
gimp
Depends: libgimp2.0
Depends: libgimp2.0
Depends: gimp-data
Depends: gimp-data
Depends: libgdk-pixbuf2.0-0
Depends: xdg-utils
Depends: libaa1
Depends: libbabl-0.1-0
Depends: libbz2-1.0
Depends: libc6
Depends: libcairo2
Depends: libfontconfig1
Depends: libfreetype6
Depends: libgcc1
Depends: libgegl-0.4-0
Depends: libgexiv2-2
Depends: libglib2.0-0
Depends: libgs9
Depends: libgtk2.0-0
Depends: libgudev-1.0-0
Depends: libharfbuzz0b
Depends: libheif1
Depends: libilmbase23
Depends: libjpeg8
Depends: liblcms2-2
Depends: liblzma5
Depends: libmng2
Depends: libmypaint-1.3-0
Depends: libopenexr23
Depends: libopenjp2-7
Depends: libpango-1.0-0
Depends: libpangocairo-1.0-0
Depends: libpangoft2-1.0-0
Depends: libpng16-16
Depends: libpoppler-glib8
Depends: librsvg2-2
Depends: libstdc++6
Depends: libtiff5
Depends: libwebp6
Depends: libwebpdemux2
Depends: libwebpmux3
Depends: libwmf0.2-7
Depends: libx11-6
Depends: libxcursor1
Depends: libxext6
Depends: libxfixes3
Depends: libxmu6
Depends: libxpm4
Depends: zlib1g
Breaks: gimp-plugin-registry
Recommends: ghostscript
ghostscript:i386
|Suggests: gimp-help-en
Suggests: <gimp-help>
gimp-help-ca
gimp-help-de
gimp-help-el
gimp-help-en
gimp-help-es
gimp-help-fr
gimp-help-it
gimp-help-ja
gimp-help-ko
gimp-help-nl
gimp-help-nn
gimp-help-pt
gimp-help-ru
gimp-help-sl
gimp-help-sv
Suggests: gimp-data-extras
Suggests: gimp-python
Suggests: gvfs-backends
gvfs-backends:i386
Suggests: libasound2
liboss4-salsa-asound2
Replaces: gimp-plugin-registry
apt install gimp
will automatically take care of any dependencies (even recursively) of that package and download and install them along withgimp
. – PerlDuck Mar 21 '19 at 12:22apt install gimp
automatically installs all dependencies. The only time you may see "depends" in errors is when a dependency is unmet. That is, there is a version conflict. – user68186 Mar 21 '19 at 12:35apt install gimp
can’t fulfill dependencies while performing an offline installation hence the mention ofapt-get download
. – Patrick Dark Mar 21 '19 at 12:37