I run Debian Jessie without a desktop environment (I use the tiling window manager i3) and like to use xdg-open to quickly open files using a preferred application. I have an ongoing problem setting the preferred app for PDF files though. This is my problem in a nutshell:

$ xdg-mime query filetype ~/Downloads/document.pdf

$ xdg-mime query default application/pdf

$ xdg-open ~/Downloads/document.pdf
[opens gimp!]

Any ideas would be hugely appreciated - this has been plaguing me for about a year. The only way I've ever managed to (temporarily) fix it is by directly editing the mimeinfo.cache and removing the reference to gimp from the application/pdf record.

And yes, /usr/share/applications/qpdfview.desktop exists and contains the correct location of the qpdfview binary. (Indeed, this .desktop file is used when I hand-edit mimeinfo.cache.)


You could attempt to manually set it via the command line using mimeopen.


$ mimeopen -d ~/test.pdf

Please choose a default application for files of type application/pdf

    1) E-book Viewer  (calibre-ebook-viewer)
    2) Document Viewer  (evince)
    3) Xournal  (xournal)
    4) GNU Image Manipulation Program  (gimp)
    5) Xpdf PDF Viewer  (xpdf)
    6) Print Preview  (evince-previewer)
    7) Inkscape  (inkscape)
    8) calibre  (calibre-gui)
    9) Other...

use application #2
Opening "/home/saml/Downloads/test.pdf" with Document Viewer  (application/pdf)

Which results in my PDF file, test.pdf opening up in Evince. From this point on Evince is the default when I use xdg-open.


  • 2
    Thanks! I still don't know why the problem existed in the first place, but at least the default now seems to persist beyond an apt-get dist-upgrade.
    – Tim
    Jun 5 '14 at 2:30
  • @Tim - glad this resolved your issue.
    – slm
    Jun 5 '14 at 2:34
  • 3
    Why does this work, but setting the default application using xdg-mime doesn't work? This is the kind of stuff that drives me insane! To elaborate, I tried xdg-mime default /usr/share/applications/evince.desktop application/pdf, and xdg-mime query filetype /some/file.pdf confirmed that the default application was set, but xdg-open completely ignored my preferences and opened Print Preview instead.
    – Hubro
    Jan 25 '16 at 12:29
  • 3
    @Hubro xdg-open is a shell script wrapper for opener commands of various desktop environment. I guess you could try running sh -x $(which xdg-open) /some/file.pdf, figuring out which actual opener command is called, then hope to find out where to searching for next...
    – Naitree
    Jun 10 '17 at 3:01
  • @sim Sorry but why was this the accepted answer? The answer seems to provide a workaround (it does not in my case) but does not actually answer the issue of why xdg-open ignores the xdg-mime query.
    – TSGM
    Dec 29 '20 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.