How to specify default applications for file types: Part 1 - Command line
Numerous apps vie to open your PDF files by default - evince, xpdf, Adobe Reader, Okular, etc. If you don't like the default as dictated by your desktop environment, you can change it.
The general idea is that default applications for file types, or 'file association', is governed by a set of configuration files. Having said that, I wish an universal method existed to change file association that is independent of the Linux distribution, the desktop environment, the file manager, and the application. In reality, the desktop environment may choose to interpret the same configuration file in different ways, or use different files altogether. Below is the general procedure that has served me well.
Before we change the default application for opening a PDF document, let's identify the current default application.
If evince is not the default program you want, you can change it to say xpdf as follows.
Before you run xdg-mime, you must make sure that:
If you are not comfortable with the command-line or xpdf does not open the PDF file by default from your file manager, the remedy is to configure the default application using your file manager. That will be the topic of part 2 of this series.
The general idea is that default applications for file types, or 'file association', is governed by a set of configuration files. Having said that, I wish an universal method existed to change file association that is independent of the Linux distribution, the desktop environment, the file manager, and the application. In reality, the desktop environment may choose to interpret the same configuration file in different ways, or use different files altogether. Below is the general procedure that has served me well.
xdg-mime
If you are comfortable with command-line, then I'd recommend that you use the xdg-mime tool first.Before we change the default application for opening a PDF document, let's identify the current default application.
The above command requires that you know the MIME type of PDF files(application/pdf). My earlier post explains how to find the MIME type of files.
$ xdg-mime query default application/pdf
evince.desktop
If evince is not the default program you want, you can change it to say xpdf as follows.
The second argument - xpdf.desktop - specifies the default application in the form of its desktop filename. Every application must have a desktop file containing configuration information in order to be registered into the desktop environment's menu system. The global desktop file must exist in the /usr/share/applications directory. Local desktop files must exist in the~/.local/share/applications directory for individual users.
$ xdg-mime default xpdf.desktop application/pdf
Before you run xdg-mime, you must make sure that:
- The desktop file preexists in the right directory for your application.
- You provide the correct desktop file name as an argument to xdg-mime.
The xdg-mime command inserts one line into the [Default Applications] section of the local configuration file for file association (~/.local/share/applications/mimeapps.list).
$ ls -l /usr/share/applications/*xpdf*.desktop
-rw-r--r-- 1 root root 181 Mar 4 10:13 /usr/share/applications/xpdf.desktop
To verify that xpdf is now indeed the default application:
application/pdf=xpdf.desktop
- Open a PDF file using the command.
$ xdg-open somefile.pdf - Double click a PDF file from inside your favourite file manager.
If you are not comfortable with the command-line or xpdf does not open the PDF file by default from your file manager, the remedy is to configure the default application using your file manager. That will be the topic of part 2 of this series.




