The German ubuntuusers wiki has a nice list of files and directories that can be used for that purpose.
Setting it globally
From my research, appending to that environment variable globally is not trivial, but here are some pointers:
- If you want to overide the existing value,
/etc/environment
is the easiest way
- Depending on the system configuration
/etc/profile
might also be a good way, because you it is executed by the shell
- Other files to try might be
/etc/X11/Xsession.d/*
and /etc/security/pam_env.conf
Setting it per-user
$HOME/.profile
(or $HOME/.zprofile
for zsh users) is suggested in multiple places, however adding the line XDG_DATA_DIRS="$HOME/.local/xdg:$XDG_DATA_DIRS"
in there rendered my desktop completely non-functional upon login
- The way that worked for me was to create
$HOME/.xsessionrc
and put the line export XDG_DATA_DIRS="$HOME/.local/xdg:$XDG_DATA_DIRS"
in there. Of course, you have to replace $HOME/.local/xdg
by the directory you want to add. Please also note that this will only set the variable for graphical applications, not for the shell (so your value won't be mentioned in echo $XDG_DATA_DIRS
), but that should not be a problem.
Recommendation
Just execute this line and log in again, and it should work:
echo export 'XDG_DATA_DIRS="/opt/myapp/share:$XDG_DATA_DIRS"' >> ~/.xsessionrc
If for whatever reason your system is nonfunctional after that, enter Recovery Mode, go into the root shell and type rm /home/<username>/.xsessionrc
and then reboot
to get back into your system.