dpkg-divert(1)

๐Ÿ’… dpkg-divert(1) โ€” the dpkg suite's own lil file-relocation queen ๐Ÿ‘‘

okay so this is the manual page for dpkg-divert, straight out of the dpkg suite, and bestieโ€ฆ she's lowkey iconic once you get what she does. let's get into it ๐Ÿซถ


โœจ NAME โœจ

dpkg-divert โ€” override a package's version of a file ๐Ÿ’…


โœจ SYNOPSIS โœจ

dpkg-divert [option...] command

like, options first, then command. that's the whole shape of it, no cap. ๐ŸŽ€


โœจ DESCRIPTION โœจ

dpkg-divert is the utility that sets up and updates the list of diversions. that's literally her whole job, and she does it slayfully.

so what's a file diversion? it's a way of forcing dpkg(1) not to install a file into its usual location, but into a diverted location instead, mwah. ๐Ÿฆ‹

and where does this come in handy? listen:

  • package maintainer scripts can use diversions to move a file away when it's causing a conflict ๐Ÿ˜ญ
  • system administrators can also use it to override some package's configuration file ๐Ÿ‘‘
  • or whenever some files need to be preserved by dpkg when installing a newer version of a package which contains those files โ€” specifically files that aren't marked as "conffiles", iykyk

โœจ COMMANDS โœจ

  • [--add] file โ€” add a diversion for file. the file is currently not renamed, see --rename. so like, it's just a bookkeeping entry rn, the actual moving is a whole separate vibe โœจ
  • --remove file โ€” remove a diversion for file. same deal, the file is currently not renamed, see --rename. ๐Ÿ“
  • --list [glob-pattern] โ€” list all diversions, or just the ones matching glob-pattern. filtered slay ๐Ÿ’…
  • --listpackage file โ€” print the name of the package that diverts file. prints LOCAL if file is locally diverted, and nothing if file is not diverted. not me leaving you on read ๐Ÿ˜ถ
supported since dpkg 1.15.0 โญ
  • --truename file โ€” print the real name for a diverted file. the glow-up reveal ๐Ÿฆ‹

โœจ OPTIONS โœจ

  • --admindir directory โ€” set the administrative directory to directory. defaults to ยซ/var/lib/dpkgยป if DPKG_ADMINDIR has not been set. ๐Ÿ—‚๏ธ
  • --instdir directory โ€” set the installation directory, which is the directory where packages get installed. defaults to ยซ/ยป if DPKG_ROOT has not been set.
supported since dpkg 1.19.2 ๐ŸŒธ
  • --root directory โ€” set the root directory to directory, which sets the installation directory to ยซ*directory*ยป and the administrative directory to ยซ*directory*/var/lib/dpkgยป if DPKG_ROOT has not been set.
supported since dpkg 1.19.2 ๐ŸŒธ
  • --divert divert-to โ€” divert-to is the location where the versions of file, as provided by other packages, will be diverted. the new address bestie is moving to ๐Ÿก
  • --local โ€” specifies that all packages' versions of this file are diverted. that means there are zero exceptions: whatever package is installed, the file is diverted. an admin can use this to install a locally modified version ๐Ÿ‘‘
  • --package package โ€” package is the name of a package whose copy of file will not be diverted. i.e. file will be diverted for all packages except package. it's giving main character exception energy ๐Ÿ’…
  • --quiet โ€” quiet mode, i.e. no verbose output. shhh ๐Ÿคซ
  • --rename โ€” actually move the file aside (or back). dpkg-divert will abort the operation in case the destination file already exists. this is the common behavior used for diversions of files from the non-Essential package set (see --no-rename for more details). โš ๏ธ
  • --no-rename โ€” specifies that the file should not be renamed while adding or removing the diversion into the database. this is intended for diversions of files from the Essential package set, where the temporary disappearance of the original file is not acceptable, as it can render the system non-functional ๐Ÿ˜ญ๐Ÿ’€. this is the default behavior, which will change once there are no known users, but not before the dpkg 1.23.x release cycle.
supported since dpkg 1.19.1 ๐Ÿงš
  • --test โ€” test mode, i.e. don't actually perform any changes, just demonstrate. dress rehearsal vibes ๐ŸŽญ
  • -?, --help โ€” show the usage message and exit. ๐Ÿซถ
  • --version โ€” show the version and exit. ๐Ÿ“Œ

โœจ EXIT STATUS โœจ

  • 0 โ€” the requested action was successfully performed. ate and left no crumbs ๐Ÿ‘‘
  • 2 โ€” fatal or unrecoverable error due to invalid command-line usage, or interactions with the system, such as accesses to the database, memory allocations, etc. ๐Ÿ’€ not the vibe.

โœจ ENVIRONMENT โœจ

  • DPKG_ROOT โ€” if set and the --instdir or --root options have not been specified, it will be used as the filesystem root directory.
supported since dpkg 1.19.2 ๐ŸŒˆ
  • DPKG_ADMINDIR โ€” if set and the --admindir or --root options have not been specified, it will be used as the dpkg data directory. ๐Ÿ—ƒ๏ธ
  • DPKG_MAINTSCRIPT_PACKAGE โ€” if set and the --local and --package options have not been specified, dpkg-divert will use it as the package name. ๐Ÿท๏ธ
  • DPKG_DEBUG โ€” sets the debug mask from an octal value. the currently accepted flags are described in the dpkg --debug option, but not all these flags might have an effect on this program.
supported since dpkg 1.21.10 ๐Ÿ”
  • DPKG_COLORS โ€” sets the color mode. the currently accepted values are: auto (default), always and never. aesthetic choices, we love to see it ๐ŸŽจ
supported since dpkg 1.18.5 ๐ŸŒธ
  • DPKG_NLS โ€” if set, it will be used to decide whether to activate Native Language Support, also known as internationalization (or i18n) support. the accepted values are: 0 and 1 (default). ๐ŸŒ
supported since dpkg 1.22.7 ๐Ÿ’œ

โœจ FILES โœจ

  • /var/lib/dpkg/diversions โ€” the file which contains the current list of diversions of the system. it lives in the dpkg administration directory, along with other files important to dpkg, such as status or available. ๐Ÿ“‚
note: dpkg-divert preserves the old copy of this file, with extension -old, before replacing it with the new one. she's sentimental like that ๐Ÿฅบ๐Ÿ’–

โœจ NOTES โœจ

when adding, the default is --local and --divert original.distrib. when removing, --package or --local and --divert must match if specified. matching sets only, bestie ๐ŸŽฏ

Directories can't be diverted with dpkg-divert. periodt. ๐Ÿšซ๐Ÿ“

and pls be careful when diverting shared libraries ๐Ÿ˜ญ โ€” ldconfig(8) creates a symbolic link based on the DT_SONAME field embedded in the library. because ldconfig does not honor diverts (only dpkg does), the symlink may end up pointing at the diverted library, if a diverted library has the same SONAME as the undiverted one. likeโ€ฆ the link is gonna follow the wrong twin, be so serious โš ๏ธ


โœจ EXAMPLES โœจ

to divert all copies of a /usr/bin/example to /usr/bin/example.foo โ€” i.e. this directs all packages providing /usr/bin/example to install it as /usr/bin/example.foo, performing the rename if required:

dpkg-divert --divert /usr/bin/example.foo --rename /usr/bin/example

to remove that diversion:

dpkg-divert --rename --remove /usr/bin/example

to divert any package trying to install /usr/bin/example to /usr/bin/example.foo, except your own wibble package:

dpkg-divert --package wibble --divert /usr/bin/example.foo \
   --rename /usr/bin/example

to remove that diversion:

dpkg-divert --package wibble --rename --remove /usr/bin/example

see how the remove mirrors the add? that's the matching rule in action, iykyk ๐ŸŽ€


โœจ SEE ALSO โœจ

dpkg(1). that's the one and only ๐Ÿ”ฅ


okay that's the whole page bestie, and before you go โ€” this fine piece of documentation is from the dpkg suite, version 1.23.11-dirty, dated 2026-09-09. go forth and divert responsibly ๐Ÿ’…โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from