TL;DR
Within WSL, append the following in your ~/.bashrc
file in order to solve the issue:
export XDG_RUNTIME_DIR=/your/chosen/directory
However, I believe that further clarification is important for this question:
What Is XDG_RUNTIME_DIR?
The $XDG_RUNTIME_DIR environment variables is one of many environment variables which make up the XDG Base Directory Specification. The official specification is available from XDG's official website, and although the spec is not long, a more concise version is available on the Arch Wiki.
Why Does It Exist?
The specification came about because UNIX, and by extent Linux, made no mention of where users or programs could store their files. (Imagine if, for example, Windows had no Documents
folder, or no Downloads
folder. Where would a downloaded file be saved? Each application would have to make its own decision on where to save it.) Thus, in the early days of UNIX, your file system could become a disorganized mess, since every application would create its own directory SOMEWHERE in the filesystem that it would use, and you would have no clue on how to find it.
The point of the XDG Base Directory specification is to provide users and programs with consistent locations to store different types of files. This helps keep your folders much more organized, and allows you to find important config, data, and runtime files much easier.
How does the spec work?
The specification provides some defaults for where files are stored, and those defaults can be overrided by setting environment variables. For example, the spec states that configuration files should be stored in ~/.config/
by default, but by setting $XDG_CONFIG_HOME
, config files instead use the path specified by the environment variable.
Why Is This a Problem on WSL?
A missing XDG environment variable usually isn't a problem, and it's also not specific to WSL. Since the application could not find the variable it was looking for, it created its own directory to store its files in. Most applications will do this and will run fine.
How Can I Fix This Warning?
You should set the environment variable for XDG_RUNTIME_DIR
in WSL before running a progam which uses it. The easiest way to do this is probably by appending the following to your .bashrc
file, so that the environment variable is set upon opening a shell.*
export XDG_RUNTIME_DIR=/your/chosen/directory
When choosing the directory, keep the following (taken from the specification) in mind:
$XDG_RUNTIME_DIR defines the base directory relative to which user-specific non-essential runtime files and other file objects (such as sockets, named pipes, ...) should be stored. The directory MUST be owned by the user, and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700.
*Fun Fact: ~/.bashrc
itself is a config file. Bash was written before the XDG Base Directory Spec was created, and thus placed its config files directly in the home directory. You can imagine how cluttered it would get if every program did this. This is the problem XDG tried to solve with their spec.