Download Debian Source Packages Using dget

This article explains how the dget utility retrieves remote source packages directly from Debian operating system repositories. You will learn about the core mechanics of dget, how it processes package description files to download complete multi-part source trees, and the practical commands used to fetch and optionally unpack Debian source code in a single workflow.

What is dget?

dget is a command-line utility provided by the devscripts package in Debian and Debian-based operating systems. Its primary function is to download Debian binary and source packages over the network. Unlike basic tools such as curl or wget, which only retrieve individual target files, dget is purpose-built to understand Debian packaging metadata.

How dget Retrieves Remote Source Packages

A Debian source package is not a single archive; it consists of multiple complementary files:

  • A Debian Source Control (.dsc) file containing metadata and checksums.
  • An upstream source tarball (.orig.tar.gz, .orig.tar.xz, or similar).
  • A Debian packaging diff or tarball (.debian.tar.xz or .diff.gz).

When retrieving remote source packages, dget performs several automated steps to fetch the complete source tree:

  1. Retrieves the .dsc File: When supplied with a URL pointing to a remote .dsc file, dget downloads this descriptor first.
  2. Parses Package Components: It reads the Files or Checksums-* sections inside the .dsc file to identify all linked archives required to build or inspect the source.
  3. Downloads Associated Files: It automatically resolves the URLs for the upstream tarball and the Debian-specific archive relative to the location of the .dsc file, downloading them to the current directory.
  4. Validates Integrity: dget verifies the cryptographic checksums (MD5, SHA-1, SHA-256) of the downloaded archives against the values declared in the .dsc file.

Key Retrieval Modes and Options

dget provides specific flags that enhance its source-fetching functionality:

  • Automatic Extraction (-x): Running dget -x <URL-to-.dsc> downloads all package components and immediately executes dpkg-source -x to extract the package into a ready-to-use source directory.
  • Extraction Without Download (-d): The -d flag instructs dget to only download the source components without extracting them.
  • APT Integration (-u or --all): When provided with a package name instead of a direct URL, dget can query configured APT repositories to locate, fetch, and verify the source package directly using repository indices.

Example Usage

To download and automatically unpack a source package using a direct repository URL:

dget -x http://deb.debian.org/debian/pool/main/h/hello/hello_2.10-3.dsc

To fetch a source package directly from configured repositories via APT:

dget -u hello

Through this automation, dget eliminates the need to manually track, download, verify, and unpack the individual files that constitute a Debian source package.