Incidentally, I have RStudio & R installed on my laptop. So I don't know why but when I double-click on .java files, they open by default in RStudio.

Every time I have to right-click and choose Sublime/Gedit as preferred choice to open these files in a proper text-editor. Can someone guide me on how to set Sublime as default for .java files(so that I can open them in Sublime with a simple double-click)?

UPDATED REQUEST: It would be much helpful if a way of doing this using terminal (or a way without using the Unity interface).

My question is partially different from How to set default program? in that I preferably need a terminal-using way.


1 Answer 1


GUI Way:

  1. Right-click the file.
  2. Go to Properties
  3. Go to the "open with" tab.
  4. Select the program you want, and click Set as Default. (I don't have Sublime, so it's not in the list)

enter image description here

Terminal way:

cd into the directory containing your file and do:

mimeopen -d your-source-code.java

Sample output:

Please choose a default application for files of type text/x-java

    1) notepad  (wine-extension-txt)
    2) LibreOffice Writer  (libreoffice-writer)
    3) gedit  (gedit)
    4) Other...

use application #

Note: credit for the terminal way goes to Ugo Hed's answer here.


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