I know that if you want to add a .desktop entry it must be added in /usr/share/applications, however, what I want is to add an extra folder where it can host .desktop files.

If I run update-desktop-database you can see that programs like snapd or flatpak create their own directories where they host their .desktop

The databases in [/usr/share/ubuntu/applications, /home/cactus/.local/share/flatpak/exports/share/applications, /var/lib/flatpak/exports/share/applications, /usr/local/share/applications, /usr/share/applications, /var/lib/snapd/desktop/applications] could not be updated.

My idea is to add a folder /opt/applications where I can save .desktop of my self-compiled applications.

3 Answers 3


According to GNOME Desktop System Administration Guide Customizing Menus : Desktop Entry Files

Desktop entry files must reside in the $XDG_DATA_DIRS/applications directory and must have a .desktop file extension. If $XDG_DATA_DIRS 1 is not set, then the default path is /usr/share is used. This also implies that user specific desktop entries may be located at $XDG_DATA_HOME/applications which is searched first. If $XDG_DATA_HOME is not set, then the default path ~/.local/share is used. Desktop entries are collected from all directories in the $XDG_DATA_DIRS environment variable. Directories which appear first in $XDG_DATA_DIRS are given precedence when there are several .desktop files with the same name.

1 $XDG_DATA_DIRS is the environment variable defined in the XDG base directory specification.

So if $XDG_DATA_HOME does not say otherwise, you can place per-user .desktop files in ~/.local/share/applications. If you want a system-wide custom location, you should be able to add it to $XDG_DATA_DIRS ex.


See also XDG Base Directory Specification

  • 1
    That works perfect. What I did was add the following in /etc/profile: "XDG_DATA_DIRS=/opt:$XDG_DATA_DIRS". Now all applications in /opt/applications are loaded by gnome, and I can see them in the launcher. Many thanks! Jul 18, 2021 at 1:13
  • A more elegant approach rather than directly editing a system file that may be overwritten by an update would be to add a one-liner script in /etc/profile.d. All these scripts are sourced by /etc/profile
    – vanadium
    Jul 19, 2021 at 9:38

You can use ~/.local/share/applications under your user's home folder to keep .desktop files that you want to have available for that user only.

  • Thanks very much for the answer, but that's not what I want to do. My idea is to have the applications isolated, to be able to copy them easily from one computer to another. However, the answer below is exactly what I was looking for. Thanks again. Jul 18, 2021 at 1:18
  • 1
    @SebastiánCastro you can put a directory inside ~/.local/share/applications (e.g., ~/.local/share/applications/my-special-applications). Personally, I'd do that instead of modifying environment variables - you just need to copy the directory in the new system's ~/.local/share/applications.
    – muru
    Jul 19, 2021 at 8:17

Not a fundamental answer to your actual question (i.e., how to add your custom directory to host .desktop launchers), but I suggest you could use /usr/local/share/applications for launchers of your self compiled applications that should be available system wide.

This directory is configured by default in Ubuntu in XDG_DATA_DIRS, and its purpose is exactly for what you are looking for, i.e., make your manually installed .desktop files available in the menu systems of any user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.