3

I want to set sublime text as my default app to open files like .cpp and .java, however any of my application lists in "Select Application" do not show sublime text.

I tried the method in this link but it didn't work: Change all associations from gedit to another application

Is there any alternative method?

Here is the output of a few related commands, if this helps:

$ ls -al /usr/share/applications/*sublime*
-rw-r--r-- 1 root root 230 Aug  8 23:50 /usr/share/applications/sublime.desktop
-rw-r--r-- 1 root root 532 Sep 23  2016 /usr/share/applications/sublime_text.desktop

$ ls -al /usr/local/share/applications/*sublime*
ls: cannot access '/usr/local/share/applications/*sublime*': No such file or directory

$ ls -al /opt
total 20
drwxr-xr-x  5 root root 4096 Aug  8 23:58 .
drwxr-xr-x 25 root root 4096 Aug 11 08:07 ..
drwxr-xr-x  3 root root 4096 Apr 21 16:02 google
drwxr-xr-x  5 root root 4096 Jul 14  2012 sublime
drwxr-xr-x  4 root root 4096 Aug  8 23:58 sublime_text

$ cat /usr/local/share/applications/sublime*.desktop
cat: '/usr/local/share/applications/sublime*.desktop': No such file or directory

$ cat /usr/share/applications/sublime_text.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=Sublime Text
GenericName=Text Editor
Comment=Sophisticated text editor for code, markup and prose
Exec=/opt/sublime_text/sublime_text %F
Terminal=false
MimeType=text/plain;
Icon=sublime-text
Categories=TextEditor;Development;
StartupNotify=true
Actions=Window;Document;

[Desktop Action Window]
Name=New Window
Exec=/opt/sublime_text/sublime_text -n
OnlyShowIn=Unity;

[Desktop Action Document]
Name=New File
Exec=/opt/sublime_text/sublime_text --command new_file
OnlyShowIn=Unity;

In response to the comments:

Output I get after running sudo fsck -f /

This is what appears a few seconds later each time the previous command is executed

Link for the screen that appears automatically after

The icon on the left (the one having a box) is Sublime Text 3, for which I want a default path. The right icon (one with the S) is for Sublime Text 2, which doesn't open due to expired build.

Left one is Sublime Text 3

Kewal Shah
  • 1,044

2 Answers2

4

Even easier... right-click on any .c++ or .java document, select Properties. Go to the Open With tab, select Sublime in the list of available applications, and click Set as Default.

If, for some reason, Sublime isn't appearing in your Unity Dashboard, or in the list of available applications, then you should reinstall Sublime, as it's missing its .desktop file. Recommend that you use Sublime 3 beta, as Sublime 2 has expired.

Update #1:

To check the file system on your Ubuntu partition...

  • boot to the GRUB menu
  • choose Advanced Options
  • choose Recovery mode
  • choose Root access
  • at the # prompt, type sudo fsck -f /
  • repeat the fsck command if there were errors
  • type reboot

Update #2:

As per @Terrance it was a problem with /usr/share/applications/defaults.list, and that Sublime Text 2 was expired and would not launch. See the accepted answer for details.

heynnema
  • 73,649
3

For those who do not wish to go through all the lengthy comments and chats related to this post, I've finally got the answer (credit: @Terrance):

  • Enter cat /usr/share/applications/sublime_text.desktop to check for the .desktop file present for ST 3.

  • Enter sudo nano /usr/share/applications/defaults.list to open the default app list.

  • Edit lines like text/x-java and text/x-c++ from whatever the default app is, to ST 3, for eg. text/x-java=sublime_text.desktop, save and exit.

enter image description here

Hope this helps :)

Kewal Shah
  • 1,044