Technoreply

How to install Sublime Text 2 on Ubuntu 12.04 (Unity)

| 245 Comments

Sublime Text is an awesome text editor. If you’ve never heard of it, you should check it out right now.

I’ve made this tutorial because there’s no installer for the Linux versions of Sublime Text. While that’s not a real problem, I feel there is a cleaner way to go around this. Also, this post will show you how to integrate Sublime Text to Unity (which, I’m glad to report, has now matured into a fully functional user interface).

So let’s get on with this. Here is my how to install Sublime Text on Ubuntu tutorial.

[This tutorial has been updated following feedback from AskUbuntu. Also, you need to do these steps using your login. Do not start by typing "sudo -s"!]

Step 1

Download the tarfile that suits you best and extract it. Here’s the command to extract tar.bz2 files:

tar xf Sublime\ Text\ 2.0.1\ x64.tar.bz2

You’ll notice that I got the 64-bit version. The reason is that it’s lightning fast. So, go for that if you can!

Step 2

You’ll get a “Sublime Text 2″ folder after extraction. This folder contains all the files that Sublime Text will need. So we have to move that folder somewhere more appropriate. Like the “/opt/” folder :

sudo mv Sublime\ Text\ 2 /opt/

Step 3

At some point you’d want to be able to call Sublime Text from the Terminal by just typing “sublime”. To do that, we’ll just create a symbolic link in “/usr/bin” like thus:

sudo ln -s /opt/Sublime\ Text\ 2/sublime_text /usr/bin/sublime

Step 4

Now that our files are at the right place, we need to create a launcher in Unity. To do this, we’re going to create a .desktop file in “/usr/share/applications”:

sudo sublime /usr/share/applications/sublime.desktop

And paste the following content:

[Desktop Entry]
Version=1.0
Name=Sublime Text 2
# Only KDE 4 seems to use GenericName, so we reuse the KDE strings.
# From Ubuntu's language-pack-kde-XX-base packages, version 9.04-20090413.
GenericName=Text Editor

Exec=sublime
Terminal=false
Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png
Type=Application
Categories=TextEditor;IDE;Development
X-Ayatana-Desktop-Shortcuts=NewWindow

[NewWindow Shortcut Group]
Name=New Window
Exec=sublime -n
TargetEnvironment=Unity

As you can see, these lines are quite straightforward. Go ahead and experiment a bit with them.

Step 5

Now you would probably want to open all text files with Sublime Text 2. The easiest way to do that is to open up the file associations list:

sudo sublime /usr/share/applications/defaults.list

And replace all occurrences of gedit.desktop with sublime.desktop.

Tada ! There you go. You now have Sublime Text 2 installed on Unity on Ubuntu 12.04, like a pro.

Here are some screenshots:

245 Comments

  1. Thanks so much; very useful for Linux noobs! :)

  2. Great! Thanks for the detailed info.

  3. Thanks for this tip!

  4. Thanks a lot, this was extremely useful!

  5. The file associations don’t work for me. I edited /usr/share/applications/defaults.list as recommended (except that the command is subl rather than sublime) , but when I click on a python file for example, it opens in gedit. Here is the line from /usr/share/applications/defaults.list:

    text/x-python=subl.desktop

    The word “gedit” appears nowhere in the file. If I type “subl” at the command prompt, sublime opens as you would expect.

    I don’t even know where to look. Have you any suggestions?

    Thanks.

    • I think I know what the problem is. When I put the sublime.desktop file in /usr/share/applications, no icon shows up on my desktop, so I put it in my Desktop directory instead, naming it subl.desktop. Apparently, the files referred to in /usr/share/applications/defaults.list won’t be found in my Desktop directory.

      Have you any idea why the icon doesn’t show up? I do have other .desktop files in my Desktop directory.

  6. Yes. I even copied the path from the .desktop file and pasted it into the terminal to check. I did find some information on why the file associations didn’t work. According to Ask Ubuntu , at

    http://askubuntu.com/questions/16580/where-are-file-associations-stored

    you need to have MIME types in the .desktop file. Examples are given in the Sublime Forum at

    http://www.sublimetext.com/forum/viewtopic.php?f=2&t=3457

  7. Thanks! This is totally awesome.

  8. That worked perfectly! Thank you!

  9. Errrr… one thing though: my icon on launchpad opens up to sublime.desktop instead of a new clean window. Any idea on how to make it work? Thanks!

  10. hey! nevermind i got it! it saves how it last shut to open just like it. thanks!

  11. Thanks a lot for this. Though I have an issue, everytime I open sublime it doesnt show me the last files I have opened but still shows the sublime.desktop and defaults.list files.

    Anyone knows how to fix it?

  12. Honesta, before closing Sublime, try closing the separate tabs first. Re-open, see if it works.

  13. Thank you. Extremely helpful and straightforward =D

  14. Awesome thanks for the simple guide!!! I didn’t know how to associate the icon

  15. Hey, thnks for share.
    It’s works! ;D

  16. Thank you very for the solution :)

  17. Pingback: Sublime Text 2 on Ubuntu 12.10 | tobyw4n

  18. This was very helpful. You are life savior. Thanks

  19. Hi mate. Does it works only for the 64bit version? I need to install the 32bit one.

    Anyway I run your code and this is what I get:

    ~$ tar xf Sublime\ Text\ 2.0.1\ x64.tar.bz2

    tar: Sublime Text 2.0.1 x64.tar.bz2: No se puede open: No existe el archivo o el directorio
    tar: Error is not recoverable: exiting now

    ~$

    Any help? Thanks in advance!
    Cheers!

  20. *”No se puede open: No existe el archivo o el directorio” means “Can’t be opened: File or directory doesn’t exist”

    Thanks!

  21. thanks! now i can use my favorite text editor without a problem.

  22. This way of doing things is utterly and completely wrong.

    For the correct method see this article:
    http://askubuntu.com/questions/172698/how-do-i-install-sublime-text-2

  23. Pingback: Instalar Sublime Text 2 en Ubuntu 12.04 utilizando Unity | Junior Developer [the blog]

  24. Thanks for the post! It’s very useful

  25. DO NOT FOLLOW THIS INSTRUCTIONS!
    Use instead:
    sudo add-apt-repository ppa:webupd8team/sublime-text-2
    sudo apt-get update
    sudo apt-get install sublime-text

  26. Pingback: 在ubuntu12.04(Unity桌面)中安装Sublime Text 2 | Zhoutall

  27. Thanks, awesome tutorial. helped a lot. I was just wondering why can’t I install sublime with apt-get ?

  28. Pingback: Приложения по умолчанию в Ubuntu | nadyarnv

  29. you made my day! thanks a lot for sharing!

  30. Thanks, very helpful and informative

    • Actually, I think the above comments are right about the correct way to do this, but this is still useful to see the manual steps.

  31. Nice One – It worked

  32. Clap – clap – clap – clap.

    Thank you!

  33. Pingback: How to install Sublime Text 2 On Ubuntu 12.04 Unity | aginanjarm

  34. Thanks alot for this!

  35. Nice tutorial. One problem, though. If you start sublime the first time with sudo, the ownership in ~/.config will be set to root:root causing all sorts of problems.

    So you might want to add that you have to open sublime atleast once as normal user before using sudo sublime.

  36. Not sure If I need to do step 4 or if I understand step 4. What do you mean by “Create a luancher in Unity”?

    Thanks though, this worked,

    Nick

  37. Hey,

    I did all the steps you taught and sublime is not appearing in the dash and when I run the command “sublime” sublime text opens but when I close the terminal sublime closes too.

    I am using ubuntu 13.04. How do I reinstall?

  38. wil this installation works for 32 bit ubuntu

  39. will this works for 32 bit ubuntu

  40. Never mind I fixed it. Villa, it should work in 32 bit Ubuntu just download the 32 bit for Linux:

    http://www.sublimetext.com/2

  41. Is sublime text 2 free to use on Linux ? it says unregistered.

  42. Yes it is. However, every now and then it will prompt you to purchase it. Might seem annoying but it is so so worth it cos it is free. Paying for it is giving back to the developer and you might possibly get updates or something. But yea it is free.

  43. Lol, this is really pathetic, all those brainiacs working on linux and they cannot handle simple app installation without terminal and problems. Like typing bunch of command will make me smarter.

    • Lol who said we were brainiacs? I have heard no such boasting? Who said command line makes anyone smarter. Nub

  44. Pingback: Установка Sublime Text 2 в Ubuntu Linux | zlovolsky blog

  45. Pingback: A long weekend with Ubuntu - Colorblind Programming

Leave a Reply

*



captcha