Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

8 Answers 8

up vote 209 down vote accepted

Install via the Package Manager(apt-get):

I know this already answered but you can simply just 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

Source: https://gist.github.com/dantoncancella/4977978

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 <henriquemoody@gmail.com>
#

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!

share|improve this answer
    
how can I launch sublime text 2 via the terminal? –  Vader Jan 25 at 3:46
    
@Vader askubuntu.com/questions/354311/… –  Jared Burrows Jan 25 at 20:11

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. 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.

share|improve this answer

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.

share|improve this answer
    
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 '12 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! –  Jorge Castro Aug 7 '12 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 '12 at 14:49

I think @Alex L. is completely right, I recommend never editting your /usr fs, add on 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=~/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=~/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.

share|improve this answer
    
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 '12 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 :). –  Mark Mikofski Nov 13 '12 at 17:54

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

share|improve this answer

I had the same problem and followed the above provided solutions without success. What did it for me was the following solution: http://stackoverflow.com/questions/21659717/sublime-text-editor-opens-with-no-menu-bar-unless-started-with-sudo

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

share|improve this answer
    
While other answers are very interesting, this one really resolved the issue for me. –  Ladislav Mrnka Apr 14 at 13:04

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.

share|improve this answer
1  
The instructions he followed don't use deb packages –  Jorge Castro Aug 6 '12 at 21:03
    
Oops, right. I remembered it being that easy. –  speter Aug 6 '12 at 21:23

First of all you must understand what is sudo and what is the point of it.

Sudo gives you the ability to run certain programs as a superuser which, in plain words, gives you access to the inner parts of the operating system. It is used to prevent unauthorized access to your computer's system which may prove to be harmful.

For information on how to disable sudo you can refer to this AskUbuntu question, although I do not recommend doing so.

Disable Sudo Permission to user from command line

share|improve this answer
    
So is there no way to give just one specific application sudo privileges automatically so I can avoid opening it with the terminal every time? Or is there any other, better way to do that? –  Michael Gruber Aug 6 '12 at 20:25
    
You could just run as root :) –  Nickolas Aug 6 '12 at 20:29
    
These links may help you ubuntu.5.n6.nabble.com/… and ubuntuforums.org/archive/index.php/t-19236.html –  Nickolas Aug 6 '12 at 20:30
1  
This is totally besides the point, sorry, especially the suggestion to run as root because of improperly-installed text editor –  Sergey Aug 6 '12 at 21:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.