Double Clicking in File Manager to Run ELF Executable Files in Ubuntu 20.04+

Since Ubuntu 16.10, the system GNU C compiler is configured with the --enable-default-pie option. Thus, GCC by default builds packages with -fPIE and -pie enabled, which causes executable files’ mime types to be application/x-sharedlib rather than application/x-executable.

It’s OK for users to launch apps either from start menu (Activities overview) since they are controlled by the ‘.desktop’ files, or using command in terminal. But, if double-clicking executable file in file manager, it may refuse to run!

For example, the mime type of Avidemux executable file in my Ubuntu 20.04 is a “shared library” like .so files. By double-clicking the file will NOT launch the app, though “Allow executing file as program” has been enabled.

Double-click executable file will NOT launch the app, since it’s considered shared library


The best choice is using -fno-pie and -no-pie options while compiling with GCC. So, the executable file will be set to application/x-executable.

As a workaround, here’s how to make your file manager treat those files built with -pie option as application/x-executable.

1.) Firstly, press Ctrl+Alt+T on keyboard to open terminal. When it opens, run command to edit the “/usr/share/mime/packages/” file as root:

sudo gedit /usr/share/mime/packages/
For non-Gnome desktop, replace gedit with your favorite text editor.
For Ubuntu 22.10+, use gnome-text-editor instead

2.) When file opens in editor, find out the section below (In my Ubuntu 20.04, it starts at line 10472):

<mime-type type="application/x-executable">
  <comment xml:lang="af">uitvoerbaar</comment>
  ... many more comment lines ...
  <comment xml:lang="zh-TW">可執行檔</comment>
  <generic-icon name="application-x-executable"/>
  <magic priority="40">
    <match type="string" value="\177ELF" offset="0">
      <match type="byte" value="1" offset="5">
        <match type="little16" value="2" offset="16"/>

Then, add following lines between <generic-icon name=”application-x-executable”/> and <magic priority=”40″>

<magic priority="60">
  <match type="string" value="\177ELF" offset="0"><match type="byte" value="1" offset="4"><match type="byte" value="1" offset="5"><match type="little16" value="3" offset="16"><match type="little32" value="52" offset="28"><match type="little32" value="3" offset="84"/></match></match></match></match></match>
  <match type="string" value="\177ELF" offset="0"><match type="byte" value="2" offset="4"><match type="byte" value="1" offset="5"><match type="little16" value="3" offset="16"><match type="little32" value="64" offset="32"><match type="little32" value="0" offset="36"><match type="little32" value="3" offset="120"/></match></match></match></match></match></match>

3.) Finally, run command to update mime datebase:

sudo update-mime-database /usr/share/mime

Now, re-check the executable in file manager. It should be application/x-executable now and double-click on file will launch the program.

via: this thread


Hi, I'm Merilyn Ne, a computer geek working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.