Where should the XDG_CONFIG_HOME variable be defined?
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Dreamlands
--
Chapters
00:00 Where Should The Xdg_config_home Variable Be Defined?
00:44 Accepted Answer Score 52
01:29 Answer 2 Score 125
02:12 Answer 3 Score 11
02:57 Answer 4 Score 3
03:07 Thank you
--
Full question
https://superuser.com/questions/365847/w...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#debian #xdg
#avk47
ANSWER 1
Score 125
You don't need to define it anywhere, unless you want to change the default.
XDG Base Directory Specification clearly says:
If
$XDG_CONFIG_HOME
is either not set or empty, a default equal to$HOME/.config
should be used.
So it is redundant to define it to the default value. All compliant applications will already use $HOME/.config
But, if you do want to change the default in a Debian/Ubuntu system, a suitable (but not the only and possibly not the best) place is:
- For a system-wide change, affecting all users:
/etc/profile
- For your user only:
~/.profile
ACCEPTED ANSWER
Score 52
In Arch Linux, this is defined by /etc/profile
, using a /etc/profile.d
script.
For Debian/Ubuntu, if there's a /etc/profile.d
– create a similar script inside; if such a directory does not exist – edit /etc/profile
itsef.
export XDG_CONFIG_HOME="$HOME/.config"
The /etc/environment
file is parsed by pam_env
, which treats it as simple name=value assignments. However, it also has /etc/security/pam_env.conf
, which supports variable expansion and can be used for this purpose.
ANSWER 3
Score 11
I've found that it works best to set environment variables via PAM. For modern Linux distos, this means /etc/environment
or $HOME/.pam_environment
(see man pam_env
). You can also set them in /etc/security/pam_env.conf
using a special syntax. Here is how I set my XDG variables in /etc/security/pam_env.conf
.
XDG_CACHE_HOME DEFAULT=@{HOME}/.xdg/cache
XDG_CONFIG_HOME DEFAULT=@{HOME}/.xdg/config
XDG_DATA_HOME DEFAULT=@{HOME}/.xdg/data
XDG_STATE_HOME DEFAULT=@{HOME}/.xdg/state
Previously I would set these variables in /etc/profile.d/custom.sh
. However, some applications start before that file is read. Switching to the PAM method solved the issue for multiple applications that behaved this way.
ANSWER 4
Score 3
For Zsh users, define it in your .zshenv
~/.zprofile
file
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"