Is there official documentation on directories like ~/.config and ~/.cache?

I've seen these directories being used by many applications and am now considering using them for my app. How do I know this is an officially supported folder and not just a flavor of the month location for a per-user cache/config?

I've been searching for something official from Ubuntu but to no avail; maybe someone else knows the proper search terms or location of this documentation. Is this something I should just accept as an un-stated standard practice location?


Yes, there is a standard: these are specified by freedesktop.org and are part of XDG Base Directory Specifications.

config-spec outlines just basic requirements, but the details are in the Base Directory Specifications. The ~/.config and ~/.cache directories are default unless configured otherwise:

There is a set of preference ordered base directories relative to which configuration files should be searched. This set of directories is defined by the environment variable $XDG_CONFIG_DIRS.

There is a single base directory relative to which user-specific non-essential (cached) data should be written. This directory is defined by the environment variable $XDG_CACHE_HOME.

...

$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

...

$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.

You may notice these specifications mostly state where data should be stored, which environment variables used, and in what manner ( desktop-neutral, efficient, etc ), but most desktops are free in implementing the "how" part of it. The GNOME-based desktops will use gsettings where as KDE users can use the same via kwriteconfig, but they both will rely on ~/.config directory in the process


Question key points

How do I know this is an officially supported folder and not just a flavor of the month location for a per-user cache/config?

These directories appear in official documentation and Filesystem Hierarchy Standard also mentions them. This is official documentation, hence the folders are officially supported.

Is this something I should just accept as an un-stated standard practice location?

Depends on the app you're creating. Is the app supposed to be configurable on per-user basis or work consistently through out the system ? FHS tells us that for system-wide stuff we should use /etc or /usr/local, but XDG directories should be used for user-specific configurations - ~/.cache and ~/.config. Of course, if application isn't dependent on user-specific settings, /var/cache can be used instead of per-user directory. Of course, you could always have single ~/.appname.conf file, a ~/.appname.db or ~/.appname/ directory to keep configurations and cache there, but that would be non-standard; not "bad" - just non-standard.

See also