XDG Base Directory Specification View article history Edit article

Published: , Updated:
Talks about: <a class="post-tag post-tag-dotfiles" href="/tags/dotfiles">dotfiles</a>, and <a class="post-tag post-tag-xdg" href="/tags/xdg">xdg</a>

The XDG Base Directory Specification has been around for a while, yet not every software has adopted it yet. Here is an incomplete list of fixes:

# use existing env variables or define new
[ -z "$XDG_CACHE_HOME"  ] && export XDG_CACHE_HOME="$HOME/.cache"
[ -z "$XDG_CONFIG_DIRS" ] && export XDG_CONFIG_DIRS="/etc/xdg"
[ -z "$XDG_CONFIG_HOME" ] && export XDG_CONFIG_HOME="$HOME/.config"
[ -z "$XDG_DATA_DIRS"   ] && export XDG_DATA_DIRS="/usr/local/share:/usr/share"
[ -z "$XDG_DATA_HOME"   ] && export XDG_DATA_HOME="$HOME/.local/share"

# gradle
export GRADLE_USER_HOME="$XDG_DATA_HOME/gradle"

# httpie
export HTTPIE_CONFIG_DIR="$XDG_CONFIG_HOME/httpie"

# npm
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npm/npmrc"
export npm_config_cache="$XDG_CACHE_HOME/npm"

# password-store
export PASSWORD_STORE_DIR="$XDG_DATA_HOME/password-store"

To make your own software XDG-aware, consider using the dirs-dev or configdir libraries.