1. Introduction

There are several tools that leverage the default packaging system in Debian and Debian-based Linux distributions. The main tool for installing packages in such environments uses local files.

In this tutorial, we discuss Debian package installation and using a URL for that purpose. First, we talk about the general concept of installing packages in Debian and its derivatives. After that, we explore how a URL might be used in the process.

We tested the code in this tutorial on Debian 11 (Bullseye) with GNU Bash 5.1.4. It should work in most POSIX-compliant environments.

2. Debian Package Installation

Installing packages on Debian-based Linux distributions is done in several ways. In every case, the packages are in the .deb binary archive format and contain the necessary files and configurations to be properly installed.

2.1. APT (Advanced Packaging Tool)

The APT system as implemented by the apt (Aptitude) package manager from the apt package, is well-known in Debian-based communities like Ubuntu.

When using apt, we can install and remove packages, perform dependency resolution, update sources, and upgrade packages:

$ apt update
[...]
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
$ apt install tcpdump
[...]
The following additional packages will be installed:
  libpcap0.8
The following NEW packages will be installed:
  libpcap0.8 tcpdump
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 625 kB of archives.
After this operation, 1,744 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
[...]
$ apt upgrade
[...]
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Here, we refresh the sources, install the tcpdump package, and attempt any pending upgrades, of which there are none.

With its separate apt-get scripting tool and the ability to query available, installed, and upgradable packages, apt is the go-to way to handle software on Debian-based systems.

Still, the official apt can’t work offline and requires source repositories to function properly.

Yet, at its core, it is a simpler utility.

2.2. dpkg (Debian PacKaGe)

The dpkg (Debian PacKaGe) offline package manager is the basis of .deb installation.

In essence, the high-level apt only serves to fetch and organize packages, while the mid-level dpkg is the way to install them:

$ ls tcpdump_4.99.3-1~bpo11+1_amd64.deb
tcpdump_4.99.3-1~bpo11+1_amd64.deb
$ dpkg --install tcpdump_4.99.3-1~bpo11+1_amd64.deb
Selecting previously unselected package tcpdump.
(Reading database ... 139801 files and directories currently installed.)
Preparing to unpack tcpdump_4.99.3-1~bpo11+1_amd64.deb ...
Unpacking tcpdump (4.99.3-1~bpo11+1) ...
dpkg: dependency problems prevent configuration of tcpdump:
 tcpdump depends on libpcap0.8 (>= 1.9.0); however:
  Package libpcap0.8 is not installed.

dpkg: error processing package tcpdump (--install):
 dependency problems - leaving unconfigured
Processing triggers for man-db (2.9.4-2) ...
Errors were encountered while processing:
 tcpdump

Of course, dependency resolution isn’t provided by dpkg, so we encounter issues when using the –install switch above.

On the other hand, there are many other functions that dpkg does support:

  • modify the local package database with –update-avail and –merge-avail
  • provide a –list of packages and use –listfiles for their contents
  • –search for and within packages
  • select packages for operations with –set-selections, –get-selections, and –selected-only
  • –compare-versions of packages with standard operators

So, leveraging these functions, apt builds on top of dpkg. On the other hand, dpkg has another tool at its base.

2.3. dpkg-deb

At the lowest level, dpkg-deb handles the basic operations with .deb binary archives:

  • –build a new archive
  • –show or get –info about an existing .deb file
  • extract all or partial –field metadata
  • list archive –contents
  • get –control information from a .deb file
  • –extract or –raw-extract (with control information) an archive
  • specify input, output, compression, and information formats

For example, we can get the contents and metadata from an existing .deb package:

$ dpkg-deb --info tcpdump_4.99.3-1~bpo11+1_amd64.deb
 new Debian package, version 2.0.
 size 471936 bytes: control archive=2100 bytes.
      32 bytes,     1 lines      conffiles
     915 bytes,    23 lines      control
     844 bytes,    12 lines      md5sums
    1608 bytes,    48 lines   *  postinst             #!/bin/sh
     894 bytes,    24 lines   *  postrm               #!/bin/sh
     215 bytes,     5 lines   *  preinst              #!/bin/sh
     215 bytes,     5 lines   *  prerm                #!/bin/sh
 Package: tcpdump
 Version: 4.99.3-1~bpo11+1
 Architecture: amd64
 Maintainer: Romain Francoise <[email protected]>
 Installed-Size: 1336
 Depends: adduser, libc6 (>= 2.14), libpcap0.8 (>= 1.9.0), libssl1.1 (>= 1.1.0)
[...]
$ dpkg-deb --contents tcpdump_4.99.3-1~bpo11+1_amd64.deb

drwxr-xr-x root/root         0 2023-01-21 17:32 ./
drwxr-xr-x root/root         0 2023-01-21 17:32 ./etc/
drwxr-xr-x root/root         0 2023-01-21 17:32 ./etc/apparmor.d/
-rw-r--r-- root/root      1514 2023-01-14 12:20 ./etc/apparmor.d/usr.bin.tcpdump
[...]

To run dpkg-deb, we can either use its binary or pass the proper options to dpkg. Thus, the latter will use dpkg-deb as requested.

Now, let’s move on to using links to install packages.

3. Install From a URL

Notably, none of the main package management tools in Debian supports direct user-supplied Universal Resource Locator (URL) downloads out-of-the-box.

Because of this, any construct for package URL installation would have to employ a third-party mechanism for creating at least a temporary local copy of a .deb package for processing.

3.1. apt Custom Repository

When it comes to tools with the function we’re after, perhaps only apt comes close to the idea with its use of repositories.

For example, we can add a custom source, which contains only the package we’re interested in:

$ echo 'deb [arch=amd64] http://xost:666/apt-repo stable main' >> /etc/apt/sources.list.d/xustom.list
$ apt-get update --allow-insecure-repositories

Yet, even these steps don’t allow an arbitrary file from a link to serve as the installation source argument. Further, custom repositories require a complex setup.

3.2. wget and curl

Indeed, the common wget and curl commands enable file downloads.

For instance, by combining wget with a call to dpkg, we can perform a package installation from a URL in a single command chain without preserving the .deb file:

$ wget 'http://ftp.debian.org/debian/pool/main/t/tcpdump/tcpdump_4.99.3-1~bpo11+1_amd64.deb' &&
  dpkg --install tcpdump_4.99.3-1~bpo11+1_amd64.deb &&
  rm tcpdump_4.99.3-1~bpo11+1_amd64.deb

In this case, we perform several actions:

  1. download tcpdump_4.99.3-1~bpo11+1_amd64.deb from http://ftp.debian.org/debian/pool/main/t/tcpdump/tcpdump_4.99.3-1~bpo11+1_amd64.deb with wget
  2. install tcpdump_4.99.3-1~bpo11+1_amd64.deb with dpkg
  3. delete the tcpdump_4.99.3-1~bpo11+1_amd64.deb file

Of course, we can replace the first command in the chain with curl:

$ curl 'http://ftp.debian.org/debian/pool/main/t/tcpdump/tcpdump_4.99.3-1~bpo11+1_amd64.deb' \
    --output 'tcpdump_4.99.3-1~bpo11+1_amd64.deb' &&
  dpkg --install tcpdump_4.99.3-1~bpo11+1_amd64.deb &&
  rm tcpdump_4.99.3-1~bpo11+1_amd64.deb

Either way, we can employ more tweaks:

  • employ the yes command and –force-* flags to make dpkg non-interactive
  • use the /tmp directory to store the download
  • suppress the file download output

Still, the basic idea would remain: we need to download any package to install it. Even if the default APT tooling supported that, it would implement a similar mechanism.

4. Summary

In this article, we discussed installing a Debian package directly from a URL.

In conclusion, while apt, dpkg, and dpkg-deb don’t accept a URL for download, we can still use one for installation by employing third-party tools.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.