How to Create a Shortcut for an Application in Ubuntu

How to Create a Shortcut for an Application in Ubuntu
Photo by Juan Gomez / Unsplash

Sometimes, when you are new to Ubuntu and need to manually download applications and run them from an executable file, you may wonder how to create a shortcut similar to those in Windows. Here, I will explain how to do it step by step.

1. Copy the application folder

First, copy the folder containing your application to the /opt/ directory with the following command:

sudo cp -r /path/to/app /opt/

2. Create the .desktop file

Check if there is a file with the .desktop extension in the copied folder. If not, you will need to create one with the following format:

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Name=dbeaver-ce
GenericName=Universal Database Manager
Comment=Universal Database Manager and SQL Client.
Path=/opt/dbeaver/
Exec=/opt/dbeaver/dbeaver
Icon=/opt/dbeaver/dbeaver.png
Categories=IDE;Development
StartupWMClass=DBeaver
StartupNotify=true
Keywords=Database;SQL;IDE;JDBC;ODBC;MySQL;PostgreSQL;Oracle;DB2;MariaDB
MimeType=application/sql

3. Explanation of the .desktop file

Here is an explanation of each part of this file:

  • [Desktop Entry]: Indicates that the file follows the desktop entry (.desktop) standard, which is used to define shortcuts in graphical desktop environments.
  • Version=1.0: Specifies the version of the desktop entry file. Not always mandatory, but can be useful.
  • Type=Application: Defines the type of the entry. In this case, it's an application. Other types can be Link or Directory.
  • Terminal=false: Indicates whether the application should run in a terminal. false means it's not needed; true would open a terminal to run the program.
  • Name=dbeaver-ce: The name of the application as it will appear in the applications menu.
  • GenericName=Universal Database Manager: A generic name that describes the type of application. Useful for users unfamiliar with the specific name.
  • Comment=Universal Database Manager and SQL Client.: A comment that provides a brief description of the application, shown as a tooltip in some desktop environments.
  • Path=/opt/dbeaver/: The working directory where the application will run. This can be useful if the application needs to run from a specific directory.
  • Exec=/opt/dbeaver/dbeaver: The command to run the application. Specifies the full path to the DBeaver executable.
  • Icon=/opt/dbeaver/dbeaver.png: The path to the icon file used to represent the application in the menu and dock.
  • Categories=IDE;Development: The categories to which the application belongs. Helps to classify it correctly in the applications menu.
  • StartupWMClass=DBeaver: The name of the main window class of the application. Useful for the desktop environment to correctly associate the window with the shortcut.
  • StartupNotify=true: Indicates whether to show a startup notification when launching the application.
  • Keywords=Database;SQL;IDE;JDBC;ODBC;MySQL;PostgreSQL;Oracle;DB2;MariaDB: Keywords that help users search for the application in the menu.
  • MimeType=application/sql: The MIME types that the application can handle. Useful for associating the application with certain file types.

4. Copy the .desktop file to the correct location

Copy the .desktop file to the /home/username/.local/share/applications directory with the following command:

sudo cp /opt/application/application.desktop /home/username/.local/share/applications

5. Assign execution permissions

Finally, give the necessary permissions to the newly copied .desktop file with the command:

chmod +x ~/.local/share/applications/application.desktop

Conclusion

By following these steps, you will have created a shortcut in Ubuntu to easily locate and open your applications. This will allow you to work more efficiently and have your favorite tools always at hand.