How Do I Create an XDG_RUNTIME_DIR

2026-05-05

In Linux distributions without systemd (such as Void, Alpine, or Gentoo), configuring the XDG_RUNTIME_DIR environment variable is required for running Wayland compositors, PipeWire, and D-Bus user sessions.

The Freedesktop base directory specification mandates that this directory must be owned by the user (0700 permissions), created on login, removed on full logout, and must not survive a reboot.


I. User-Space and Scripting Solutions

These operate in the user's login shell. Due to privilege and phase limitations, they rarely meet the specification securely.


II. System-Level and Session Management Solutions

These operate within the PAM stack using root privileges, resolving permission and DM compatibility issues.


III. Conclusion and Final Selection

Considering security, complexity, and background process compatibility, pam_dumb_runtime_dir is my choice.

As the author states:

"Creates an XDG_RUNTIME_DIR directory on login per the freedesktop.org base directory spec. Flaunts the spec and never removes it, even after last logout. This keeps things simple and predictable."

Why this is acceptable:

  1. Memory Management: /run is almost always a tmpfs (RAM-based filesystem). Although files persist after logout, they are wiped instantly upon reboot or power loss.
  2. Safety: By refusing to clean up, it avoids the "murderous" behavior of pam_rundir, ensuring tmux sockets and background daemons remain accessible until the system shuts down.
  3. Simplicity: It avoids background daemons, complex counting logic, and external dependencies.