16

What's the default value for $XDG_DATA_HOME variable? I get an empty line with:

echo $XDG_DATA_HOME

According to the Free Desktop XDG Base Directory Environment variables specification, it might be equal to $HOME/.local/share?

Slim
  • 477
  • 1
  • 4
  • 10
g0lem
  • 457
  • 3
  • 7
  • 13

2 Answers2

12

As report in XDG Base Directory Specification environment variables aren't set by default bug, Ubuntu doesn't set XDG variables.

According to FreeDesktop Base Directory Specification:

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

Applications that implement this specification must implement this behaviour, so if $XDG_DATA_HOME is not defined they must use $HOME/.local/share as default.

There are some implementation of this specification, like: Glib, libghc-xdg-basedir-prof and pyxdg

If you want to override this value, you should define XDG variable in /etc/profile or better in /etc/profile.d as described in Where should the XDG_CONFIG_HOME variable be defined?

Lety
  • 5,994
  • 2
  • 28
  • 36
7

If it's unset, you can set it thus in your ~/.profile:

export XDG_DATA_HOME=${XDG_DATA_HOME:="$HOME/.local/share"}

This keeps any value already set, else sets it to the default value specified in the XDG Base Directory Specification

Tom Hale
  • 3,358
  • 5
  • 16
  • 33
  • Better to define this in your `~/.xprofile`, or as the accepted answer suggests `/etc/profile`. If your default shell is zsh, you may also get by using your `~/.zshenv` file because everything will read that file – smac89 Dec 05 '20 at 03:39
  • Yeah, I agree it depends heavily on which Linux distribution we are concerned with. For Arch the choice is obviously `.xprofile` at `$HOME`... – Kris Stern Dec 16 '21 at 13:26
  • Better yet, `~/.profile` for both `{ba,z}sh` and console logins also. Answer updated – Tom Hale Dec 26 '21 at 17:00