XDG RUNTIME DIR: Difference between revisions

From Alpine Linux
No edit summary
(Consolidate intro)
 
Line 1: Line 1:
Various daemons and applications depend on <code>XDG_RUNTIME_DIR</code> being set, including [[Wayland]], [[PipeWire]] and others.
Various daemons and applications depend on the <code>XDG_RUNTIME_DIR</code> environment variable being set, including [[Wayland]], [[PipeWire]] and others. This variable should point to a private, ephemeral directory owned by the current user. The exact semantics and details for this variable (and the directory to which it points) are documented in the [https://specifications.freedesktop.org/basedir/latest/#variables XDG base directory specification].
 
The exact semantics and details for this variable (and the directory to which it points) are documented in the [https://specifications.freedesktop.org/basedir/latest/#variables XDG base directory specification].


A few mechanisms exist to properly initialise this variable and its corresponding directory, as described below. Only one should be used for a user's session; configuring multiple of these mechanisms will lead to misbehaviours.
A few mechanisms exist to properly initialise this variable and its corresponding directory, as described below. Only one should be used for a user's session; configuring multiple of these mechanisms will lead to misbehaviours.

Latest revision as of 08:52, 2 April 2026

Various daemons and applications depend on the XDG_RUNTIME_DIR environment variable being set, including Wayland, PipeWire and others. This variable should point to a private, ephemeral directory owned by the current user. The exact semantics and details for this variable (and the directory to which it points) are documented in the XDG base directory specification.

A few mechanisms exist to properly initialise this variable and its corresponding directory, as described below. Only one should be used for a user's session; configuring multiple of these mechanisms will lead to misbehaviours.

Initialising via elogind

When using elogind as a seat manager, it exports XDG_RUNTIME_DIR and other XDG environment variables automatically for each session. No further configuration is required. XDG_RUNTIME_DIR would be set as /run/user/$(id -u) by elogind.

Initialising via pam_rundir

pam_rundir is a PAM module that provides the runtime directory variable. Installing the package pam-rundir takes care of dependencies and no further configuration is required. XDG_RUNTIME_DIR would be set as /run/user/$(id -u) by pam_rundir.

dumb_runtime_dir is functionally equivalent and has cleaner, simpler code, but is not currently packaged in Alpine.

Initialising via mkrundir

mkrundir is an executable that can be used to initialise the runtime directory explicitly by each user. To use mkrundir, install the package mkrundir available in testing repository. XDG_RUNTIME_DIR would be set as /run/user-$UID by mkrundir. In your shell init script (e.g.: ~/.profile include an entry as follows at the top of the file

Contents of ~/.profile

... export XDG_RUNTIME_DIR=$(mkrundir) ...

As per mkrundir website, this might have issues inside containers, due to privilege escalation.

Initialising manually in /tmp

Generally, care should be taken when configuring the XDG_* variables manually as this configuration may have errors or conflict with other utilities that do this automatically. Use this only on a system that's not using elogind and other solutions outlined above cannot handle this.

The XDG_RUNTIME_DIR can be initialised manually by adding below snippet to shell init scripts (e.g.: ~/.profile):

Contents of ~/.profile

if test -z "${XDG_RUNTIME_DIR}"; then export XDG_RUNTIME_DIR=/tmp/xdg/"${UID}"-xdg-runtime-dir if ! test -d "${XDG_RUNTIME_DIR}"; then mkdir -p "${XDG_RUNTIME_DIR}" chmod 0700 "${XDG_RUNTIME_DIR}" fi fi

See also