DOKK / manpages / debian 12 / dpkg / dpkg-divert.1.en
dpkg-divert(1) dpkg suite dpkg-divert(1)

dpkg-divert - override a package's version of a file

dpkg-divert [option...] command

dpkg-divert is the utility used to set up and update the list of diversions.

File diversions are a way of forcing dpkg(1) not to install a file into its location, but to a diverted location. Diversions can be used through the Debian package scripts to move a file away when it causes a conflict. System administrators can also use it to override some package's configuration file, or whenever some files (which aren't marked as “conffiles”) need to be preserved by dpkg, when installing a newer version of a package which contains those files.

[--add] file
Add a diversion for file. The file is currently not renamed, see --rename.
Remove a diversion for file. The file is currently not renamed, see --rename.
List all diversions, or ones matching glob-pattern.
Print the name of the package that diverts file (since dpkg 1.15.0). Prints LOCAL if file is locally diverted and nothing if file is not diverted.
Print the real name for a diverted file.

Set the administrative directory to directory. Defaults to «/var/lib/dpkg» if DPKG_ADMINDIR has not been set.
Set the installation directory, which refers to the directory where packages get installed (since dpkg 1.19.2). Defaults to «/» if DPKG_ROOT has not been set.
Set the root directory to directory, which sets the installation directory to «directory» and the administrative directory to «directory/var/lib/dpkg» (since dpkg 1.19.2) if DPKG_ROOT has not been set.
divert-to is the location where the versions of file, as provided by other packages, will be diverted.
Specifies that all packages' versions of this file are diverted. This means, that there are no exceptions, and whatever package is installed, the file is diverted. This can be used by an admin to install a locally modified version.
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.
Quiet mode, i.e. no verbose output.
Actually move the file aside (or back). dpkg-divert will abort 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).
Specifies that the file should not be renamed while adding or removing the diversion into the database (since dpkg 1.19.1). 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, but that will change in the dpkg 1.20.x cycle.
Test mode, i.e. don't actually perform any changes, just demonstrate.
-?, --help
Show the usage message and exit.
Show the version and exit.

0
The requested action was successfully performed.
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.

If set and the --instdir or --root options have not been specified, it will be used as the filesystem root directory (since dpkg 1.19.2).
If set and the --admindir or --root options have not been specified, it will be used as the dpkg data directory.
If set and the --local and --package options have not been specified, dpkg-divert will use it as the package name.
Sets the debug mask (since dpkg 1.21.10) 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.
Sets the color mode (since dpkg 1.18.5). The currently accepted values are: auto (default), always and never.

/var/lib/dpkg/diversions
File which contains the current list of diversions of the system. It is located 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.

When adding, default is --local and --divert original.distrib. When removing, --package or --local and --divert must match if specified.

Directories can't be diverted with dpkg-divert.

Care should be taken 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.

To divert all copies of a /usr/bin/example to /usr/bin/example.foo, i.e. 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

dpkg(1).

2023-05-11 1.21.22