Default applications

From ArchWiki
Revision as of 11:12, 2 November 2013 by Lonaowna (Talk | contribs) (move some content around with xdg-open)

Jump to: navigation, search

zh-cn:Default Applications

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: need better introduction (second point is not described) (Discuss in Talk:Default applications#)

There are numerous places to configure default applications on Linux. This page will explain the most used ones: using MIME types and using environment variables.

Using 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;....

A list of MIME type and corresponding default application is stored in $XDG_DATA_HOME/applications/mimeapps.list (for a single user; $XDG_DATA_HOME defaults to ~/.local/share) and /usr/share/applications/defaults.list (system wide). This list can be edited by using xdg-mime.

This file looks like this:

[Default Applications]


[Default Applications]

A distribution could also ship a /usr/share/applications/mimeapps.list to provide system-wide defaults, but Arch Linux does not do this. To override these system-wide defaults, one can add [Added Associations] section is used to specify preferred (default) applications in decreasing order of preference for the specified MIME type. The [Removed Associations] section is used to explicitly remove any previously inherited associations.


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.

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="">
	<mime-type type="application/x-foobar">
		<comment>foo file</comment>
		<icon name="application-x-foobar"/>
		<glob pattern="*.foo"/>

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]

Note that Categories should be set appropriately for the application type (in this example, a multimedia app).

  • Now update the mime database with:
$ 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. I haven't tried setting this field yet; please update this wiki page if you have any info about using OnlyShowIn.

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):

export EDITOR="nano"
export BROWSER="firefox"


Applications don't appear in the Open With... context menu (of a file manager)

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.