Altering the Default Program for Opening a File Type in Ubuntu

Feedback

Question:

How do I set a specific program (like emacs) to open files (such as file.tex) on Ubuntu?


Solution 1:


Launch Nautilus and select any of the files. From the pop-up menu, click on “Properties” and then use the “Open with” feature to customize your preferences.


Solution 2:


Rather than making changes to
defaults.list
, I prefer using the xdg-mime tool which allows me to quickly identify the pdf viewer and switch from Adobe to KPDF.

$xdg-mime query default application/pdf
AdobeReader.desktop
$xdg-mime default kde-kpdf.desktop application/pdf
$xdg-mime query default application/pdf
kde-kpdf.desktop

To launch a file with your favored application, xdg-open can be utilized.

$xdg-open file.pdf


Solution 3:

As pointed out by Manni, the program used to open a file can be modified via the Properties tab.

Revision:
Refer to Chris089’s response for further information. Rather than following my previous suggestion of directly editing the files, I recommend using the tool mentioned in Chris089’s answer. While it’s still beneficial to have an understanding of the mime-types and their associations, modifying the file through the tool is the preferred method.

In case you prefer a solution that involves text, or if you wish to examine the configuration of file-associations for various types.

  • The default.list file in ~/.local/share/applications stores file associations for individual users. You have the ability to modify it to reference a .desktop file that represents the respective executable.

To view the default applications, open the file located at ~/.local/share/applications/defaults.list. In this file, you can see that the Google Earth application, represented by the desktop file Google-googleearth.desktop, is set as the default for various file types, including application/vnd.google-earth.kml+xml, application/keyhole, and application/vnd.google-earth.kmz.

  • The global system-wide associations are stored in the file located at /usr/share/applications/defaults.list. To make a system-wide change for all audio files, one must refer to this file to obtain all the mime-types. The user can choose to modify the entries directly in this file or override them in their local defaults.list.

$ cat
/usr/share/applications/defaults.list
| grep ^audio

audio/3gpp=totem.desktop

audio/ac3=totem.desktop

audio/AMR=totem.desktop

audio/AMR-WB=totem.desktop

audio/basic=totem.desktop

audio/midi=totem.desktop

audio/mp4=totem.desktop

audio/mpeg=totem.desktop

audio/mpegurl=totem.desktop

audio/ogg=totem.desktop

audio/prs.sid=totem.desktop

audio/vnd.rn-realaudio=totem.desktop

audio/x-ape=totem.desktop

audio/x-flac=totem.desktop

audio/x-gsm=totem.desktop

audio/x-it=totem.desktop

audio/x-m4a=totem.desktop

audio/x-matroska=totem.desktop

audio/x-mod=totem.desktop

audio/x-mp3=totem.desktop

audio/x-mpeg=totem.desktop

audio/x-mpegurl=totem.desktop

audio/x-ms-asf=totem.desktop

audio/x-ms-asx=totem.desktop

audio/x-ms-wax=totem.desktop

audio/x-ms-wma=totem.desktop

audio/x-musepack=totem.desktop

audio/x-pn-aiff=totem.desktop

audio/x-pn-au=totem.desktop

audio/x-pn-realaudio=totem.desktop

audio/x-pn-realaudio-plugin=totem.desktop

audio/x-pn-wav=totem.desktop

audio/x-pn-windows-acm=totem.desktop

audio/x-realaudio=totem.desktop

audio/x-real-audio=totem.desktop

audio/x-sbc=totem.desktop

audio/x-scpls=totem.desktop

audio/x-speex=totem.desktop

audio/x-tta=totem.desktop

audio/x-wav=totem.desktop

audio/x-wavpack=totem.desktop

audio/x-vorbis=totem.desktop

audio/x-vorbis+ogg=totem.desktop

audio/x-xm=totem.desktop

This is the specification for Desktop Entry that explains the significance and purpose of a .desktop file instead of utilizing the executable’s path.

Frequently Asked Questions