This is an extension to the question how to include an environment variable in the launcher? . This question explains how to use the environment variable for the Exec part of the .desktop file but not the icon

an example:

[Desktop Entry]
Name=My Application name
Comment=a comment
Exec=sh -c '$HOME/.bin/path/to/bin'
Icon= $HOME/.bin/path/to/icon

This Launcher will work but the icon is not shown. I can't use something like

Icon=sh -c '$HOME/.bin/path/to/icon'

for the icon... what to do instead?

2 Answers 2


Honestly the best way to use an icon in a launcher is to make sure the icon file is in the icon search path. Referring to the freedesktop.org icon directory scheme and base directory definitions, icons should be searched for in at least the following directories on Ubuntu systems:

  • $HOME/.icons
  • $HOME/.local/share/icons
  • /usr/local/share/icons
  • /usr/share/icons
  • /usr/share/pixmaps

So if you want to use your own icon and do not have root privileges, install the icon into either $HOME/.icons or $HOME/.local/share/icons. Using the latter, you can even mimic the system icon directory structure with multi-resolution icons using the same base name under directories like $HOME/.local/share/icons/hicolor/48x48/apps and $HOME/.local/share/icons/hicolor/256x256/apps.

If the icon is in one of these searchable directories, you can simply use Icon=myapp in the .desktop file.

  • Icon=myapp does not work for me, I need to provide the full path (Icon=/usr/share/icons/myapp.png). Does the icon need to be named myapp.png, and I need to omit the extension in the *.desktop file? Or does the icon need to be in a subdirectory named myapp.
    – Ratnanil
    Commented Jan 13, 2023 at 6:59

You can try something like this:

[Desktop Entry]
Exec=sh -c "mv %k %k-bak && sed -e "s,^Icon=.*,Icon=$HOME/.bin/path/to/icon.png,g" %k-bak > %k && chmod +x %k; rm %k-bak"

This will add the relative Icon path to the .desktop file after you run it.

Some more details:

%kstands for the path of the .desktop file

  1. mv %k %k-bak creates a backup file

  2. sed -e "s,^Icon=.*,Icon=$HOME/.bin/path/to/icon.png,g" ... replace the old Icon path with the current $HOME... path ("^" -> beginning line, is here really importand to not replace the command self) and create the new .desktop file

  3. chmod +x %k make the new .desktop file executable

  4. rm %k-bak remove the old backup file

You can add your own commands after the Icon path was changed or before.

Inspired by https://stackoverflow.com/a/3464561 and https://askubuntu.com/a/345123/265974

  • i don't have root access, so I can't use /usr/share.... and I want to sync the starter between different computers, which is why I need a more generic soluteion with $HOME or something like this...
    – Jonas
    Commented Jun 3, 2014 at 15:41
  • @Jonas i've updated my answer.
    – TuKsn
    Commented Jun 3, 2014 at 22:24
  • 1
    thanks! Yes that might work...but isn't there any easier solution? Why does gnome shell not evaluate environment variables?
    – Jonas
    Commented Jun 4, 2014 at 9:08
  • Sorry i dont't know.
    – TuKsn
    Commented Jun 4, 2014 at 9:10

You must log in to answer this question.

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