Default applications
Related articles
Default applications can be set for use with particular file types (e.g. the Firefox web browser for HTML
files). Where undertaken, files may be opened and/or edited with the desired application much faster and more conveniently. There are also numerous methods to configure default applications in Linux. This page will explain the most common methods: File Managers, MIME types, and environment variables.
MIME types and desktop entries
The modern method to start applications is using Desktop entries. This way, programs can advertise which kind of files (to be exact: what MIME-types) they can open. For instance, gimp.desktop
states MimeType=image/bmp;image/gif;...
.
freedesktop.org recommends how to specify default (preferred) applications for MIME-types in their Association between MIME types and applications standard. This involves writing into files called mimeapps.list
which are looked up in the following order of paths:
Path | Usage |
---|---|
$HOME/.config/$desktop-mimeapps.list |
user overrides, desktop-specific |
$HOME/.config/mimeapps.list |
user overrides |
/etc/xdg/$desktop-mimeapps.list |
sysadmin and vendor overrides, desktop-specific |
/etc/xdg/mimeapps.list |
sysadmin and vendor overrides |
$HOME/.local/share/applications/$desktop-mimeapps.list |
for compatibility but now deprecated, desktop-specific |
$HOME/.local/share/applications/mimeapps.list |
for compatibility but now deprecated |
/usr/local/share/applications/$desktop-mimeapps.list and /usr/share/applications/$desktop-mimeapps.list |
distribution-provided defaults, desktop-specific |
/usr/local/share/applications/mimeapps.list and /usr/share/applications/mimeapps.list |
distribution-provided defaults |
In this table, $VARS
are environment variables and $desktop
is the name of the current desktop (in lowercase), for example kde
, gnome
, xfce
, etc.
The default application for a given MIME-type is specified by writing into the group [Default Applications]
in the mimeapps.list
file. In the following example, application default1.desktop
(if it is installed) will be used for mimetype1
, and otherwise default2.desktop
(if it is installed and default1.desktop
is not):
[Default Applications] mimetype1=default1.desktop;default2.desktop
The applications are written as a semicolon-separated list of desktop file IDs.
In the absence of such an entry, the next mimeapps.list
in the path hierarchy will be checked. Once all levels have been checked, if no entry could be found, then programs can pick any of the .desktop files associated with the MIME-type, taking into account added and removed associations as per these other groups which may be specified in mimeapps.list
files:
[Added Associations] mimetype1=foo1.desktop;foo2.desktop;foo3.desktop mimetype2=foo4.desktop [Removed Associations] mimetype1=foo5.desktop
The [Added Associations]
group defines additional associations of applications with MIME-types, as if the .desktop file was listing this MIME-type in the first place. The [Removed Associations]
group removes associations of applications with MIME-types, as if the .desktop file was not listing this MIME-type in the first place. The entries in [Default Applications]
should also be considered to add an association between application and MIME-type in the same manner.
File managers
Most file managers will allow for specific applications to be set as the defaults for various file types. New defaults may also be set at any time. For example, to set a default application using thunar, the native file manager for Xfce:
-
right-click
the file-type desired - Select
Open with another application
- Select the desired application
- Ensure that the
Use as default for this kind of file
check-box is ticked - Click the
Open
button.
The general process will be very similar for most other popular file managers, including PCManFM and spacefm.
Gnome Control Center
If it is installed, run gnome-control-center
, open System
> Details
> Default Applications
.
gnome-defaults-list
gnome-defaults-listAUR is available from the AUR, and contains a list of file-types and programs specific to the GNOME desktop. The list is installed to /etc/gnome/defaults.list
.
Open this file with a text editor. Here you can replace a given application with the name of the program of your choice. For example, the media-player totem
can be replaced with another, such as vlc
. Save the file to ~/.local/share/applications/defaults.list
.
xdg-open
xdg-open is a desktop-independent tool for starting default applications. Many applications invoke the xdg-open
command internally. xdg-open uses xdg-mime to query ~/.local/share/applications/mimeapps.list
(among other things; if you use a mainstream DE like GNOME, KDE or LXDE, xdg-open might try using their specific tools before xdg-mime) to find the MIME type of the file that is to be opened and the default application associated with that MIME type.
See xdg-open for more information.
Mimeo
Mimeo is a command-line file association manager and launcher that can be used by applications such as web browsers and mail clients to open files. It adheres to the freedesktop.org specifications while providing optional support for the deprecated ~/.local/share/applications/mimeapps.list
which is still commonly used. It also supports a custom and versatile regular-expression-based association file that can be used to associate arbitrary strings with applications (e.g. open youtube URLs with VLC or open protein database files with PyMol). Mimeo is available from the AUR (mimeoAUR) as well as Xyne's repos.
Custom file associations
The following method creates a custom mime type and file association manually. This is useful if your desktop does not have a mime type/file association editor installed. In this example, a fictional multimedia application 'foobar' will be associated with all *.foo
files. This will only affect the current user.
First, create the file ~/.local/share/mime/packages/application-x-foobar.xml
:
$ mkdir -p ~/.local/share/mime/packages $ cd ~/.local/share/mime/packages $ touch application-x-foobar.xml
Then edit ~/.local/share/mime/packages/application-x-foobar.xml
and add this text:
<?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="application/x-foobar"> <comment>foo file</comment> <icon name="application-x-foobar"/> <glob-deleteall/> <glob pattern="*.foo"/> </mime-type> </mime-info>
Note that you can use any icon, including one for another application.
Next, edit or create the file ~/.local/share/applications/foobar.desktop
to contain something like:
[Desktop Entry] Name=Foobar Exec=/usr/bin/foobar MimeType=application/x-foobar Icon=foobar Terminal=false Type=Application Categories=AudioVideo;Player;Video; Comment=
Note that Categories should be set appropriately for the application type (in this example, a multimedia app).
Now update the applications and mime database with:
$ update-desktop-database ~/.local/share/applications $ update-mime-database ~/.local/share/mime
Programs that use mime types, such as file managers, should now open *.foo
files with foobar. (You may need to restart your file manager to see the change.)
Maintaining settings for multiple desktop environments
The OnlyShowIn
field of a .desktop file may be useful; see this page.
Using environment variables
Most non-graphical programs use Environment variables, such as EDITOR
or BROWSER
. These can be set in your terminal's autostart file (e.g. ~/.bashrc
):
~/.bashrc
export EDITOR="nano" export BROWSER="firefox"
Troubleshooting
Sometimes, a certain application will not appear in the right-click Open With... dialog. To fix this problem, locate the .desktop
file in /usr/share/applications
, edit it as root, and add %U
to the end of the Exec=
line. For example, Kile currently has this problem; you need to edit /usr/share/applications/kde4/kile.desktop
and change the line reading Exec=kile
to read Exec=kile %U
. Also, please file a bug against the upstream project if you notice this problem.
You may also have to edit the MimeType
list in the .desktop
file if you install extensions that allow an application to handle additional MIME types.