Is there an apt command to download a deb file from the repositories to the current directory?
I am often interested in the installation triggers (postinst, postrm) or certain parts of packages (like /usr/share and /etc). Currently, I am running the next command to retrieve the source code:
apt-get source [package-name]The downside is, this file is often much bigger than the binary package and does not reflect the installation tree.
Right now, I am downloading the packages through :
- Search for
[package-name] - Select the package
- Click on amd64/i386 for download
- Download the actual file
This takes too long for me and as someone who really likes the shell, I would like to do something like the next (imaginary) command:
apt-get get-deb-file [package-name]I could not find something like this in the apt-get manual page. The most close I found was the --download-only switch, but this puts the package in /var/cache/apt/archives (which requires root permissions) and not in the current directory.
7 Answers
You can use the download sub-command of apt, apt-get or aptitude. For example, if $PKG is the package you want, any of these will do:
apt-get download $PKG
apt download $PKG
aptitude download $PKGThis doesn't require root privileges. The same can also be approximated using apt-get and wget:
wget $(apt-get install --reinstall --print-uris -qq $PKG | cut -d"'" -f2)This will, however, fetch all packages required to install the package, so you can attempt to limit it instead:
wget $(apt-get install --reinstall --print-uris -qq $PKG | cut -d"'" -f2 | grep "/${PKG}_")You can also put a wget line into a function, to be able to use it as a command apt-download with the package name as a parameter:
function apt-download { wget -c $(apt-get install --reinstall --print-uris -qq $1 | cut -d"'" -f2); }Note the modifications: The $PKG is replaced with $1 and the -c parameter enables continuing interrupted downloads.
6sudo apt-get -o dir::cache::archives="/path/to/folder/" -d install packageNote:
You need to create an folder named partial in destination folder.
4In Ubuntu 14.04 (apt package version 1.0.1ubuntu2, I believe), apt-get includes the download command to download the given package as a .deb in the current directory.
For example, suppose we want to download the file manager Ranger:
$ apt-get download rangerResults in:
$ ls . | grep ranger
ranger_1.6.0-1_all.deb 1 If you want to download all deb packages from a list, you can do this:
cat path/to/text/file.txt | xargs apt-get install --reinstall --print-uris -qq $PKG | cut -d"'" -f2 | xargs wgetJust put one package name per line. Like in a requirements.txt file. For example, with contents like this:
apache2-mpm-event
curl
dmidecode
ethtool
libapache2-mod-wsgi
libapache2-mod-pythonHope this helps. ;)
sudo apt-get install devscripts
dget [package-name]
/var/cache/apt/archives is world readable. After apt-get -d, just extract it from there to your home directory. Run dpkg -e /var/cache/apt/archives/foo_version.deb foo while in your home directory and the control files will be dumped into foo/.
You can use command debget which is included in the package debian-goodies.
Install it with:
sudo apt install debian-goodiesDownload packages using:
debget <package_name>For example:
debget debian-goodiesWhich will download debian-goodies_0.79_all.deb in your current directory (do pwd to print your current working directory).