Wednesday, May 8, 2013

[How to] Install Sublime Text 2 in Linux

How to install Sublime Text 2 in Linux

¿De qué está hablando? Versión en español

A very nice text editor


If you are looking for a nice text editor or if you simply got tired of Gedit or Geany, Sublime Text won't let you down.

This editor has a lot of features, like Geany but it's more unique. You can improve your experience by installing plugins.

This editor supports a lot of languages like C, HTML, PHP, Java, LISP, Bash...

Installation

If you want to fully install this editor you need to follow the next steps:

Step 1.

Go the download page of Sublime and select the architecture that corresponds you.

Step 2.

Extract the files with the following command:

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

Step 3.

You will need to move them to the /opt directory (most of the manually installed programs will go there). You need root privileges.

sudo mv Sublime\ Text\ 2 /opt

Step 4.

If you want to be able to launch Sublime from the Terminal you will need to create a symbolic link. You can use the name that you want "sublime_text", "sexy-editor"... in my case I decided to call it sublime.

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

Step 5.

If you use Ubuntu and Unity, you can integrate Sublime to Unity creating the following file (you can adapt this to your desktop):

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

Put the following content in that file and modify it if you need it so it will integrate to the desktop of your choice:

[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



Step 6.

If you want to use Sublime Text to open all your text files you need to change the default applications.

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

Replace all the iterations of gedit.desktop with sublime.desktop. You can use Ctrl + D to select all the iterations that you want and then you just need to write what you want. It will replace all the selections that you made.

Step 7.

Install the Package Manager. That way you can download different plugins for this text editor. You need to give some permissions to the configuration file of Sublime. Use the following command (replacing {your username} with your actual username):

sudo chown -R {your username}:{your username} "/home/{your username}/.config/sublime-text-2"

Then launch Sublime as root.

sudo sublime

Open the Console, go to "View">"Show Console" and put the following command:

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

Then you only need to relaunch Sublime Text and you are good to go.

3 comments: