How to Create a .Desktop File for Your Application in Linux

Create Desktop File Linux 00 Featured Image

A .desktop file is simply a shortcut that is used to launch applications in Linux. Without the .desktop file, your application won’t show up in the Applications menu and can’t be launched with third-party launchers such as Ulauncher and Albert.

Most applications, when installed, will create the .desktop files automatically and place themselves in the “Application” menu for quick access. However, if you compile a program from source or download an app in archive format, this may not be the case, and you may have to open the terminal to execute the binary every time you want to use it. Obviously, this can become a very tedious and troublesome step. This tutorial shows how you can create a .desktop file for any application you use that can be launched from the “Application” menu.

Also read: Top 6 Linux Desktop Environments of 2024

How to Create Desktop Launchers

A .desktop file is a simple text file that holds information about a program. It is usually placed in “~/.local/share/applications” or “/usr/share/applications/,” depending on whether you want the launcher to be accessible for your local account onlly or for everyone. If you navigate to either directory in your File Manager, you will see quite a few .desktop files that correspond with the installed apps on your computer.

For demonstration purposes, we are creating a .desktop file for Super Tux Kart, a kart racing game we like to play sometimes. A version is available in the Ubuntu repos, but this is often behind the latest stable version.

The only way to get the latest and greatest release is by downloading a tar archive, extracting it and executing a file which will launch the game.

Also read: How to Delete a Directory in Linux

You can follow along with whichever program you want to create a launcher for, and it should work the same way.

Note: the following steps assume you have the archive for the program you want to create a launcher for in your “Downloads” folder.

  1. Navigate to the directory where the archive is stored, right-click it and select “Extract here.”
Create Desktop File Linux 01 Extract Archive
  1. Once the extraction is complete, change to the newly created folder and find the executable.
  2. Right-click it and select “Run as a Program” to launch the program just to ensure it is working.
Create Desktop File Linux 02 Test Run Program
  1. In some cases, you won’t see the “Run” option in the menu, often because the executable is a .text file. You can get around this by executing it via the terminal.
Create Desktop File Linux 03 Run Program Terminal
  1. If you’ve confirmed that the application works when you launch it, you can exit it.
  2. Launch your text editor and paste the following into the empty text file:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=/path/to/executable
Name=Name of Application
Icon=/path/to/icon

Note: You’ll need to change the “Exec” field to the path to the executable and “Name” field to the name of the application. Most programs provide an icon somewhere in the archive, so don’t forget to include that as well. In our case, the launcher file for Super Tux Kart looks like the following image.

Create Desktop File Linux 04 Sample Desktop File
  1. Save the file in the “~/.local/share/applications” folder as “application-name.desktop”. The “.local” folder is a hidden folder in your “Home” directory and “Show Hidden Files” mode will have to be enabled for you to view it. If you want it to be globally accessible, run the following command in the terminal:
sudo mv ~/.local/share/applications/<application-name.desktop> /usr/share/applications/

Note: don’t forget to change <application-name.desktop> to the actual name of the .desktop file.

  1. Once done, open the “Applications” menu on your desktop to find the .desktop app.
Create Desktop File Linux 05 Working Desktop Shortcut

The method described here should work on all mainstream Linux-based operating systems. Here’s another screenshot showing Super Tux Kart in Xubuntu’s application launcher (XFCE).

Create Desktop File Linux 06 Desktop Shortcut Xfce

Also read: How to Fix the “No Installation Candidate” Problem in Ubuntu

How to Copy .Desktop Files

As discussed above, you can obtain a .desktop file from a program that you have installed through a repository. This is helpful if you want to create a custom .desktop file as a way of fixing a broken package in Ubuntu.

For the most part, each Linux distribution is largely similar in its structure, so while this section will heavily focus on Ubuntu 22.04, you can still use these instructions in your favorite desktop environment.

  1. To start, open a File Manager from your desktop. In this case, we are opening Nautilus, as it is the default for Ubuntu.
  1. Press the “Other Locations” entry in Nautilus’s left side bar.
Create Desktop File Linux 07 Sample File Manager Nautilus
  • This brings up a list of all the system locations in your machine. Press “Computer.”
Create Desktop File Linux 08 Open Root Filesystem
  1. Go to “/usr/share/applications.” This directory contains the .desktop files that your desktop manager uses to create its Application Menu.
Create Desktop File Linux 09 Application Shortcuts Folder
  1. Copy the application you want to create a shortcut to. For instance, right-click on “firefox-esr.desktop” and select “Copy.”
Create Desktop File Linux 10 Copy Desktop File
  1. Go back to your desktop and place the .desktop file by right-clicking and selecting “Paste.”
Create Desktop File Linux 11 Paste Desktop File
  1. Right-click on your .desktop file and select “Allow Launching.” Doing this will set the permission bits so that your desktop environment can use this file to launch your program.
Create Desktop File Linux 12 Set Launch Permissions

Also read: How to View WebP Images on Linux

How to Create .Desktop Files With a Third-Party Program

Aside from editing and copying .desktop files, it is also possible to create shortcuts in Linux through a Graphical User Interface (GUI) program. This is useful if you are not comfortable with editing configuration files.

Unlike the previous methods, this will require you to install a program like Arronax, which may not be present in your distribution’s repository. Despite that, it is still possible to use it by obtaining a copy from the developer’s website. To install the GUI in Ubuntu, follow the below instructions.

  1. Add a third-party repository by running the following command:
sudo add-apt-repository ppa:diesche/stable
Create Desktop File Linux 13 Add New Repository
  1. Iinstall the GUI program by running the following command:
sudo apt install arronax
  1. On the other hand, if you are installing it through a tarball, you need to unpack the archive using tar:
tar xvzf /home/$USER/Downloads/arronax-0.8.1.tar.gz
Create Desktop File Linux 14 Unpack Package Archive
  1. Run Arronax by either running the command below or typing “arronax” while in the Application Menu. This will bring up a window where you can create and save .desktop files.
./setup.py && ./run.py
Create Desktop File Linux 15 Arronax Menu Item
  1. To create your first shortcut using Arronax, click the “New” icon in Arronax’s Menu Bar to create a template that you can use for your shortcut.
  2. Provide the shortcut’s name and a file path to your program. For example, we are creating a .desktop file for Firefox by typing “Firefox” in the “Title” field and /bin/firefox-esr in the “Command” field.
Create Desktop File Linux 16 Arronax Sample Program
  1. Press the green arrow in Arronax’s Menu Bar to save the shortcut.
Create Desktop File Linux 18 Green Arrow Highlight
  1. In this example, we’re saving it as “Firefox.desktop” in our desktop directory.
Create Desktop File Linux 17 Save Desktop File 1
  1. Right-click this .desktop file and select “Allow Launching” to set the permission bits for it, as shown above.

Also read: How to Set Up Bluetooth in Linux

Frequently Asked Questions

Is it possible to use a .desktop file even if I am using a window manager?

No, a .desktop file will not work on most window managers, as it lacks the necessary support for the “XDG Menu” specification. While it is possible to create a .desktop file in a window manager, it will not show up as a desktop shortcut. One way to recreate this mechanism is by using shell scripts alongside the Simple X Hotkey Daemon.

Is it possible to create a .desktop file for CLI and TUI applications using Arronax?

Yes! You can easily create a .desktop file for a program that runs in the terminal, which is useful if you are already using TUI programs and want to have a quick way to access them.

To do this using Arronax, create a new .desktop shortcut by providing both a “Title” and a “Command,” then toggle the “Run in Terminal” option and save the new shortcut.

Is it possible to hide a desktop shortcut from an Application Menu?

Yes! It is possible to modify a .desktop file to not show on your Applications Menu by adding a single line of code in the file that you want to edit. For example, if you want to hide Firefox from your Applications Menu, open the “firefox-esr.desktop” file in “/usr/share/applications”. From there, add Hidden=true at the end of the file, then restart your computer to apply the changes.

Image credit: Charles-Adrien Fournier via Unsplash All screenshots by Ramces Red.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red
Ramces Red - Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.