481

I installed Sublime Text 2 on 12.04 as per this tutorial.

However I don't have adequate permissions when launching the program from the Unity launcher. For example I cannot install packages, or if I add a folder to the sidebar when I close Sublime and reopen, the folder is no longer listed. If I run sudo sublime in the terminal all changes remain after closing.

I've tried chown-ing the Sublime Text 2 folder in usr/lib sudo chown -R mylogin:mylogin /usr/lib/"Sublime Text 2" but this seemed to have no effect.

1

13 Answers 13

803

Install via the Package Manager(apt-get):

Simply add to your packages:

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

Run Sublime-Text on terminal

subl

Install Manually via Terminal:

Download from the Sublime Site:

32-bit:

wget http://c758482.r82.cf2.rackcdn.com/Sublime\ Text\ 2.0.2.tar.bz2
tar vxjf Sublime\ Text\ 2.0.2.tar.bz2

64-bit:

wget http://c758482.r82.cf2.rackcdn.com/Sublime\ Text\ 2.0.2\ x64.tar.bz2
tar vxjf Sublime\ Text\ 2.0.2\ x64.tar.bz2

For Both:

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

Source: http://www.tecmint.com/install-sublime-text-editor-in-linux/

Install Manually via Script:

Check out this nice script on Github("Install Sublime Text on Fedora.") that you can run, just make sure to edit the "*.tar.bz2" in the script to download the latest version of Sublime Text!

#!/usr/bin/env bash
# Usage: {script} [ OPTIONS ] TARGET BUILD
# 
#   TARGET      Default target is "/usr/local".
#   BUILD       If not defined tries to get the build into the Sublime Text 3 website.
# 
# OPTIONS
#
#   -h, --help  Displays this help message.
#
# Report bugs to Henrique Moody <[email protected]>
#

set -e

if [[ "${1}" = '-h' ]] || [[ "${1}" = '--help' ]]; then
    sed -E 's/^#\s?(.*)/\1/g' "${0}" |
        sed -nE '/^Usage/,/^Report/p' |
        sed "s/{script}/$(basename "${0}")/g"
    exit
fi

declare URL
declare URL_FORMAT="http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_%d_x%d.tar.bz2"
declare TARGET="${1:-/usr/local}"
declare BUILD="${2}"
declare BITS

if [[ -z "${BUILD}" ]]; then
    BUILD=$(
        curl -Ls http://www.sublimetext.com/3 |
        grep '<h2>Build' |
        head -n1 |
        sed -E 's#<h2>Build ([0-9]+)</h2>#\1#g'
    )
fi

if [[ "$(uname -m)" = "x86_64" ]]; then
    BITS=64
else
    BITS=32
fi

URL=$(printf "${URL_FORMAT}" "${BUILD}" "${BITS}")

read -p "Do you really want to install Sublime Text 3 (Build ${BUILD}, x${BITS}) on \"${TARGET}\"? [Y/n]: " CONFIRM
CONFIRM=$(echo "${CONFIRM}" | tr [a-z] [A-Z])
if [[ "${CONFIRM}" = 'N' ]] || [[ "${CONFIRM}" = 'NO' ]]; then
    echo "Aborted!"
    exit
fi

echo "Downloading Sublime Text 3"
curl -L "${URL}" | tar -xjC ${TARGET}

echo "Creating shortcut file"
cat ${TARGET}/sublime_text_3/sublime_text.desktop |
    sed "s#/opt#${TARGET}#g" |
    cat > "/usr/share/applications/sublime_text.desktop"

echo "Creating binary file"
cat > ${TARGET}/bin/subl <<SCRIPT
#!/bin/sh
if [ \${1} == \"--help\" ]; then
    ${TARGET}/sublime_text_3/sublime_text --help
else
    ${TARGET}/sublime_text_3/sublime_text \$@ > /dev/null 2>&1 &
fi
SCRIPT

echo "Finish!"

Source: https://gist.github.com/henriquemoody/3288681

This helped me and I hope it helps everyone else as well!

12
  • 5
    how can I launch sublime text 2 via the terminal?
    – Vader
    Jan 25, 2014 at 3:46
  • @Vader askubuntu.com/questions/354311/… Jan 25, 2014 at 20:11
  • 1
    Also, to use sublime as your default text editor instead of gedit, you should edit: /usr/share/applications/defaults.list by putting subl instead gedit.
    – Bacara
    Mar 9, 2015 at 19:53
  • 1
    worked perfectly in ubuntu 14.04 using the second method ppa:webupd8team/sublime-text-3
    – suhailvs
    May 4, 2015 at 6:15
  • What is ppa:webupd8team/sublime-text-2? Is it secure and trustworthy? Is there an installation guideline on the main website of the sublime?
    – 000
    May 18, 2015 at 7:57
67

Basically, your problem is that you're using a wrong article :) If it was on an SE site I would down-vote it.

Manually copying stuff which does not come from Ubuntu repositories into /usr is WRONG. This directory is managed by Ubuntu's package manager and messing with it is going to cause you trouble at some point or another - for example, the next time you upgrade your system Sublime will likely be removed without a trace.

Running the program as root is even wronger, especially in the case of SublimeText which has its own package manager which basically downloads stuff from Internet and lets it run on your computer. A simple typo in a plugin could destroy all data on your machine.

A proper solution, if you want to install the program system-wide, would be to find/build a .deb file and install it - this way package manager would be aware of the package. Webupd8 maintains a PPA for SublimeText2, so you can just use that.

However, there's a much lazier solution which I am personally using - just unpack SublimeText somewhere in your home directory, create a bin directory in your home directory and symlink sublime_text executable into that directory:

mkdir ~/bin
ln -s ~/wherever/sublime/is/sublime_text ~/bin

After which you'll be able to run Sublime Text by typing sublime_text in the console, from any directory. This does not require root privileges at all and the editor runs just fine.

The article also does some shell integration, such as registering sublime_text as a default editor and adding an icon, and I was too lazy to do that - however, I'm sure that it can be done without messing with system-wide settings.

This does not explain, however, the problems with permissions you're having - SublimeText stores all its settings in your home folder anyway, so even if you installed it system-wide it should not have problems. What probably happened is that you started it the first time with superuser privileges (i.e. from the sudo shell), so the editor's config directory (in ~/.config/sublime-text-2) is owned by root now. You need to do something like

sudo chown -R yourusername:yourusername /home/yourusername/.config/sublime-text-2

to fix this.

2
  • Could you fully explain the bit about creating a bin directory and symlinking it? Feb 5, 2015 at 17:45
  • @hellocatfood: I've expanded my answer a bit
    – Sergey
    Feb 5, 2015 at 21:14
21

Here is how to solve this.

1) undo all the steps in the linked webpage in reverse order.

1a) if you didn't save a copy of your original defaults.list then open a terminal and run

sudo cp /usr/share/applications/defaults.list /usr/share/applications/defaults.list.bak && cat /usr/share/applications/defaults.list.bak | sed "s/sublime\.desktop/gedit.desktop/g" | sudo tee /usr/share/applications/defaults.list

2) get the version of sublime you want and extract it to the current directory.

3) in bash cd to the directory where you extracted sublime

4) mv Sublime\ Text\ 2 ~/.local

4a) if you want to be able to run sublime from the command line then run mkdir -p ~/bin && ln -s ~/.local/Sublime\ Text\ 2/sublime_text ~/bin/sublime. The default .bashrc will add ~/bin to your $PATH the next time your shell launches.

5) Make a file called sublime.desktop in ~/.local/share/applications/ and paste the following inside.

[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=~/.local/Sublime\ Text\ 2/sublime_text
Terminal=false
Icon=~/.local/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=~/.local/Sublime\ Text\ 2/sublime_text -n
TargetEnvironment=Unity

6) test -e ~/.local/share/applications/defaults.list -a 1$(grep -sc \[Default\ Applications\] ~/.local/share/applications/defaults.list) != 10 || echo "[Default Applications]" >> ~/.local/share/applications/defaults.list; grep gedit.desktop /usr/share/applications/defaults.list | sed "s/gedit\.desktop/sublime.desktop/g" >> ~/.local/share/applications/defaults.list

7) done.

It should now be installed locally in your home directory and you should have no more issues with permissions.

3
  • The OP would probably have to delete/chown ~/.config/sublime-text-2 directory as that's what is causing the problem. Anyway, thanks for the detailed instructions.
    – Sergey
    Aug 7, 2012 at 2:07
  • 2
    Please make a new "How do I install Sublime" question with answer, it would be a nice contribution so that people can do it right instead of following blog posts we can't fix! Aug 7, 2012 at 14:48
  • @Sergey Yeah that would probably also work. A big issue with the linked directions though is that they ask you to install something to your /usr/lib manually, which is never good.
    – Alex L.
    Aug 7, 2012 at 14:49
7

You can also also download the Debian package for your particular architecture from the sublime website

and then run the following;

cd download_path
sudo dpkg -i package.deb

for example if my download for a 64 bit architecture is in the Downloads directory and is called sublime-text_build-3080_amd64.deb then I will run

cd ~/Downloads
sudo dpkg -i sublime-text_build-3080_amd64.deb

In my case it was sublime text 3, you can get for your sublime text 2 also

6

I think @Alex L. is completely right. I recommend never editting your /usr fs, add-on commercial software should be installed in either /opt for multi-user or ~/opt for single user (see Linux Filesystem Hierarchy especially /opt and /home). Here are just a few more additions to make it really nice.

  1. You don't have to move your app to .local or /local; I usually just leave them in ~/opt (n.b.: the tilde is your home directory or $HOME).

    user@machine:~$ cd ~/Downloads
    user@machine:~/Downloads$ cd wget http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%202.0.1.tar.bz2
    user@machine:~/Downloads$ cd ..
    user@machine:~$ tar -C ~/opt -xf "~/Downloads/Sublime Text 2"
    
  2. Make a symlink to sublime_text in ~/bin, but call it sublime; see step 4a in Alex L.'s answer above.

    user@machine:~$ ln -s ~/opt/Sublime\ Text\ 2/sublime_text ~/bin/sublime
    
  3. Same as Alex L.'s step 5, make a file called sublime.desktop in ~/.local/share/applications/ but add %f after sublime in the Exec field so that you can open it from Nautilus, as described in this post. Also don't escape spaces for the Icon field and use the full path, no tilde. Replace <user> with your username.

    [Desktop Entry]
    Version=1.0
    Name=Sublime Text 2
    GenericName=Text Editor
    Exec=/home/<user>/bin/sublime %f
    Terminal=false
    Icon=/home/<user>/Sublime Text 2/Icon/48x48/sublime_text.png
    Type=Application
    Categories=Development;IDE;TextEditor
    X-Ayatana-Desktop-Shortcuts=NewWindow
    
    [NewWindow Shortcut Group]
    Name=New Window
    Exec=/home/<user>/bin/sublime -n
    TargetEnvironment=Unity
    
  4. You shouldn't have to log off, but if it doesn't show up in your dash, right away maybe you do. Then look for a file to open in Nautilus, right-click and select Open With Other Applicaton ... then Show other applications button at the bottom, find Sublime Text 2 in the list, select it and hit Select. Your file should open in Sublime Text 2, and from now on for files of that type you will see Sublime Text 2 already listed as an option. You can also set it as the default from Nautilus by right-clicking, selecting Properties then Open With and finally Set as default button after highlighting Sublime Text 2. Of course you could have used Add to select Sublime Text 2 to open the file type from the Properties window as well.

2
  • 1
    Without the full path for the Exec key the desktop file will not work in all situations. (though it is true that it will work most of the time).
    – Alex L.
    Nov 13, 2012 at 16:40
  • Thanks Alex L.! Very good to know! I'm super happy with my sublime-text-2 setup now, and so far everything is working great. Very disappointed that people are being misled by this post :(. However now it seems that there is a ppa provided by WebUpd8 that users can install via apt-get :). Nov 13, 2012 at 17:54
5

Type the following commands in the terminal, 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
4
  1. Download the deb package from the official site.

  2. Install the package by $sudo dpkg -i path_to_the_file.deb

  3. Start the program from /opt/sublime_text/sublime_text

4

Installing Snap on Ubuntu

sudo apt install snapd

Installing Sublime text

sudo snap install sublime-text --classic

Note: snapd is only works for ubuntu 16.04 or later versions

0
3

As mentioned by Leonard Kakande, you can install it from official repository. It works for Sublime Text 3 only, though.

Run the following commands in your terminal:

(1) Install the GPG key:

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

(2) Select the channel to use:

Stable

echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

Dev

echo "deb https://download.sublimetext.com/ apt/dev/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

(3) Update apt sources and install Sublime Text

sudo apt-get update
sudo apt-get install sublime-text
2

I recently made this for your convenience: https://github.com/TCattd/sublime-text-linux-installer

A Sublime Text 2 and Sublime Text 3 bash script installer. Just download one of the scripts, ST2 or ST2.

For ST2 is: st2install

Put ir in your home folder. Then form a terminal (and in the same home folder) run:

sudo bash st2install

That will take care of all.

You can upgrade with that very same script too, in case a new ST2 version pop out. Same apply for installing/upgrading ST3.

And both versions, using those installers, can live together without conflicts.

Hope it helps ;)

1

I had the same problem and followed the above provided solutions without success. What did it for me was the following solution.

Essentially:

  1. Close all of your sublime app instances

  2. Open up the sublime desktop file

    sudo gedit /usr/share/applications/sublime-text-2.desktop
    
  3. Edit the file by replacing

    Exec=/usr/bin/subl %F
    

    with

    Exec=env UBUNTU_MENUPROXY=0 /usr/bin/subl %F
    
  4. Delete sublime profile configuration folders

    rm -fR ~/.config/sublime-text-2
    
  5. Start sublime from the top menu or shortcut
1
  • While other answers are very interesting, this one really resolved the issue for me. Apr 14, 2014 at 13:04
0

Install Sublime On Debian/Ubuntu To install sublime on Debian and Ubuntu, run the following commands.

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

$ sudo apt-get install apt-transport-https

$ echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

$ sudo apt-get update $ sudo apt-get install sublime-text

https://www.itsmarttricks.com/category/linux-tutorials/

-1

Maybe there has simply something gone wrong during the installation. I'm using Sublime Text 2 on 12.04 and it doesn't need sudo. I suggest you type sudo apt-get purge sublime-text in a terminal (depends on which version you've installed. Use the tab key after having typed the line until "subl" twice - each installed version will be displayed). This will completely remove the installation. After that, go to the homepage of sublime text and make sure you download the .deb package. Browse the package in Nautilus (home folder), right-click on the .deb-package and choose "open with Software Center". In the Software Center, click install and follow the instructions. After that you should be able to launch the application without sudo.

1
  • 1
    The instructions he followed don't use deb packages Aug 6, 2012 at 21:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .