How to set the default document reader in Ubuntu 16.04?

Solution 1:

In my knowledge you can set a default app through xdg-mime.

xdg-mime default okular.desktop application/pdf

To check if it worked:

xdg-mime query default application/pdf

Solution 2:

Default applications seem to be set globally in the /usr/share/applications/defaults.list as association pairs between application and file. User specific file associations can be set in the file ~/.local/share/applications/defaults.list. This file may not exist - perhaps after a fresh Ubuntu install - but can be created by the user.

I now use a script like the one below to associate applications to file types. In this example Okular is associated with all document types (replacing Evince).

#!/bin/bash

if [ -e ~/.local/share/applications/defaults.list ]
then
    echo "The file exists"
    sed 's/evince/okular/' ~/.local/share/applications/defaults.list > ~/.local/share/applications/defaults.list
else
    echo "The file does not exist"
    sed 's/evince/okular/' /usr/share/applications/defaults.list > ~/.local/share/applications/defaults.list
fi