I've installed some app under /opt/myapp, which has a /opt/myapp/share directory. As I finish installing, it tells me:

Note that '/opt/myapp/share' is not in the search path
environment variables, so applications may not
be able to find it until you set them. The
directories currently searched are:

- /usr/share/gnome
- /home/joeuser/.local/share/flatpak/exports/share
- /var/lib/flatpak/exports/share
- /usr/local/share
- /usr/share

What's the right way to add directories to that list - system-wide and as a single user?

2 Answers 2


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.


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.

  • 1
    Note that I switched to Arch now, which doesn't support xsessionrc by default (looks like it's read by the login manager) and also doesn't seem to set XDG_DATA_DIRS to a default value, so i am looking into moving it.
    – xeruf
    Commented Mar 1, 2021 at 10:39
  • If you are using Wayland, you can do XDG_DATA_DIRS=<your_dir>:$XDG_DATA_DIRS in ~/.config/environment.d/envvars.conf for per-user config. Commented Dec 20, 2022 at 20:15
  • I set all these kinds of variables in my .zshenv now as that is my default shell
    – xeruf
    Commented Dec 21, 2022 at 22:52

I'm not sure about system wide.. but as a single user (which is accessible sytem-wide) I include this line in my ~/.profile file.


And you can adapt that to meet your own needs.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .