59

I am running Ubuntu 15.10.

My /usr/share/applications/sublime_text.desktop contains the following:

[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;

When I right-click on a markdown file (xxx.md) in Gnome Files (formerly "Nautilus"), I cannot see "Sublime Text" as a choice, even when I select "View All Applications".

I even tried adding %F to the lines Exec=/opt/sublime_text/sublime_text -n and Exec=/opt/sublime_text/sublime_text --command new_file in the [Desktop Action Window] and [Desktop Action Document], respectively, but it did not change anything.

I even ran sudo update-desktop-database.

What am I doing wrong?

Ralph
  • 875
  • 1
  • 9
  • 14
  • What version of Sublime are you running, and how did you install it? Have you added it to /usr/share/applications/defaults.list and replaced all the gedit.desktop entries? – MattDMo Feb 11 '16 at 16:18
  • I am running Sublime Text v3 (build 3103) for x64 installed form a .deb file. I did not edit either defaults.list or gedit.desktop. What should those files contain? – Ralph Feb 11 '16 at 21:06
  • 1
    Markdown doesn't have the MIME type text/plain, which is the only one registered in this desktop file. – David Foerster Feb 11 '16 at 23:23

6 Answers6

126

Copy the contents of /usr/share/applications/sublime_text.desktop to ~/.local/share/applications/sublime_text.desktop

Or simply use:

cp -it ~/.local/share/applications /usr/share/applications/sublime_text.desktop

Then in the terminal type: sudo update-desktop-database

David Foerster
  • 36,264
  • 56
  • 94
  • 147
agustaf
  • 1,376
  • 6
    Great solution. It would be nice if you also offered the explanation as to why this works. – padawanTony Nov 26 '16 at 20:57
  • 1
    @padawanTony There is a cache for file types (MIME types) in Ubuntu and each MIME type has related applications. Copying the file copies over correct sublime_text.desktop file which is able to relate to text files (contains line MimeType=text/plain; which default file in local folder does not contain). Then executing the sudo-command will update MIME cache (reads in updated .desktop file) and the relation will appear in context menu. I cannot unfortunately say why we have buggy .desktop file under .local in the first place. – MF.OX Apr 07 '17 at 15:03
  • Would simply deleting the sublime_text.desktop entry from the local folder then also work? Would the OS usually make a fresh copy of it? – minitauros Feb 09 '18 at 09:27
  • @agustaf, I am using ubuntu 16.04 but /.local/ folder is not located could you please help – SagarPPanchal Nov 15 '18 at 04:56
  • @SagarPPanchal You could try creating it with mkdir -p ~/.local/share/applications and see if copying the file over still works. If that doesn't work you may want to post a new question. – agustaf Nov 16 '18 at 05:07
  • @David Foerster are those cp params the right way around? All the previous edits have cp /usr/share/... ~/.local/share/... – ConorSheehan1 Mar 13 '19 at 12:31
  • @con--: If you look at the 3rd invocation form and the -t option from the cp(1) manual page you’ll understand the (apparently) reversed argument order. In short, -t removes ambiguity whether the destination is a directory or something else. – David Foerster Mar 14 '19 at 15:27
8

In case an old cache does something wrong, simply delete it and let a system make new one for you.

rm ~/.local/share/applications/sublime_text.desktop

It works for me.

Naofumi
  • 181
  • 1
  • 2
7

I tried all the options as mentioned in other answers. But, somehow it didn't help me (I'm using Ubuntu 16.04 and installed Sublime-text_build-3126_amd64).

I see this problem occurs in my system only when I install Sublime editor using the package (sublime-text_build-3126_amd64.deb) downloaded from the site. However, installing Sublime from terminal resolves this problem.

I'm yet to figure out technically why there is a difference in the application behaviour between its 2 modes of installation. However, as it works for me, am sharing it here so that it might be helpful for others. The working alternative is:

  1. Uninstall the existing sublime package. Use Synaptic Pkg Mgr and do a complete removal.
  2. Install sublime using the commands:

    For Sublime-Text-2:

    sudo add-apt-repository ppa:webupd8team/sublime-text-2
    sudo apt-get update
    sudo apt-get install sublime-text
    

    For Sublime-Text-3:

    sudo add-apt-repository ppa:webupd8team/sublime-text-3
    sudo apt-get update
    sudo apt-get install sublime-text-installer
    

    Enter subl command to begin instantly.

  3. Right-click on the file you wish to open in the Sublime editor. Now, you could find the application "Sublime text" listed in the menu. Also, you could set the editor as default for the file-type by setting it in the file's properties.

Thanks!:)

umash07
  • 101
2

Do this only if you installed sublime text using 'Ubuntu Make'(umake). Ubuntu Make(umake) makes installing and updating developer tools easier. Type this in terminal.

cat ~/.local/share/applications/sublime-text.desktop

Contents of sublime-text.desktop file will be displayed. Note the following line in the file:

Exec=/home/ja9/.local/share/umake/ide/sublime-text/sublime_text

You need to change that line. Type:

sudo nano ~/.local/share/applications/sublime-text.desktop

The nano text editor is opened, edit that line to

Exec="/home/ja9/.local/share/umake/ide/sublime-text/sublime_text" %F

Make sure you typed capital F, not small. Press 'Ctrl+O'. Press 'enter'. Press 'Ctrl+X'. Type:

sudo update-desktop-database

Problem solved :) , if not, restart system. Note: nano is very good for editing, give it a try(tries)

abyt23
  • 41
0

This worked for me on Ubuntu 20.04

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -

sudo apt-add-repository "deb https://download.sublimetext.com/ apt/stable/"

sudo apt install sublime-text

0

Open /usr/share/applications/defaults.list (a symlink to /etc/gnome/defaults.list on my system) in Sublime and replace all instances of gedit.desktop with sublime_text.desktop. Save the file and restart your computer - it may be sufficient to log out and back in, but I suspect you'll need to completely quit Gnome for the settings to be reloaded. Once you've logged back in, Sublime Text should be listed in the right-click menu as the default choice for Markdown files, and it should be in the "Open With" menu as well for all file types that can be opened in a text editor.

EDIT:

Here are the contents of my current /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;
MattDMo
  • 2,125
  • 1
  • 13
  • 18
  • Still no joy. There must be something funny about my Sublime Text installation. I compared the .desktop file with the one Atom, and there is no substantial difference, but Atom appears in the open with list. – Ralph Feb 12 '16 at 13:56
  • @Ralph very strange. I just edited my answer with the current contents of my sublime_text.desktop, and it looks exactly the same as the one in your question. My next suggestion would be to completely uninstall Sublime (you can leave ~/.config/sublime-text-3) and reinstall it fresh. Double-check /usr/share/applications/defaults.list again to make sure all the gedit (and perhaps atom as well?) entries have been replaced with sublime_text, then reboot and try again. – MattDMo Feb 12 '16 at 14:35