What is xdg_runtime_dir

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 1, 2026

Quick Answer: XDG_RUNTIME_DIR is an environment variable in Linux and Unix systems that specifies a directory for user-specific runtime files. It follows the XDG Base Directory specification and is typically located at /run/user/[uid], with files automatically cleaned up after logout.

Key Facts

Overview

XDG_RUNTIME_DIR is an environment variable that defines a directory where applications can store user-specific runtime data on Linux and Unix systems. This directory is part of the XDG Base Directory specification, a standardization effort by freedesktop.org to provide consistent locations for various types of files across different applications and desktop environments.

Purpose and Function

The runtime directory serves as a temporary storage location for files that exist only during a user's session. Unlike configuration files or cached data, runtime files are meant to be ephemeral and are automatically purged when the user logs out. This includes items like socket files, named pipes, lock files, and temporary session-specific data.

Location and Permissions

Typically, XDG_RUNTIME_DIR points to /run/user/[uid], where [uid] is the user's numeric user ID. This directory is created automatically by systemd or similar session managers. Importantly, only the user who owns the directory (and the root user) can access it, with permissions typically set to 700 (read, write, execute for owner only). This strict permission model ensures security and prevents other users from accessing sensitive runtime data.

Common Use Cases

Best Practices

When developing applications for Linux, developers should respect the XDG Base Directory specification and use XDG_RUNTIME_DIR for appropriate runtime data. Applications should check if the environment variable is set and use fallback locations if needed, though on modern systemd-based systems, it's virtually always available.

Related Questions

What is the difference between XDG_RUNTIME_DIR and /tmp?

XDG_RUNTIME_DIR is user-specific and more secure, while /tmp is system-wide and accessible to all users. Runtime files are automatically cleaned up per-user session, whereas /tmp files may persist longer.

How do you set XDG_RUNTIME_DIR if it's not set?

On modern Linux systems with systemd, XDG_RUNTIME_DIR is automatically set by the session manager. You can manually check or set it by exporting the variable in your shell: export XDG_RUNTIME_DIR=/run/user/$(id -u)

What are other XDG Base Directory variables?

Related variables include XDG_CONFIG_HOME (configuration files), XDG_DATA_HOME (application data), XDG_CACHE_HOME (cache files), and XDG_STATE_HOME (state files). These provide a standardized directory structure.

Sources

  1. XDG Base Directory SpecificationCC0-1.0
  2. Wikipedia - XDG Base DirectoryCC-BY-SA-4.0

Missing an answer?

Suggest a question and we'll generate an answer for it.