0

I am new to using Ubuntu 12.04 and noticed two different ways of launching Sublime Text 2 via Terminal window, first being sudo and the other being gksu.

Upon using both I noticed it's launching different instances of Sublime Text 2 with different instances of files loaded that I've opened on both including saving snippets. Launching with gksu saves the snippets into root/etc/etc and sudo saves them into the home/user/etc/etc.

What is the preferable way to launch Sublime Text 2 in the terminal window? Sudo or gksu and why?

Thanks for the input!

webdev
  • 741
  • 5
  • 16
  • Closers: I believe this is on-topic; it (Sublime Text 2) falls within the acceptable category of “software development tools”. – icktoofay Jul 01 '14 at 02:06
  • @icktoofay, I agree, but I also feel the answer would be primarily opinion based, so it should be closed in any case – Simon MᶜKenzie Jul 01 '14 at 02:33
  • @Simon: If there were no difference between `sudo` and `gksu`, and there were no alternative better than either, that might be the case. However, judging by the answers on the question (full disclosure: one of them is mine), there *is* a (minor) difference between them, and there *is* an alternative besides the two that is objectively better. – icktoofay Jul 01 '14 at 02:37

2 Answers2

3

I don't know about Sublime Text in particular, but in general, it is bad form to run an editor as the superuser; it will either use the settings of the superuser (okay, but you probably want your customizations) or it will put the files in your home directory, not owned by you (so if you ever want to use your editor as yourself again, you might not be able to change any preferences).

Typically, if you need to edit a file that only root can write to, you should be using sudoedit, which will copy the file to a file you can edit, run the editor as yourself, and then copy the changes back. And if you need to edit a file that you don't need to be the superuser to write to, even sudoedit is not necessary: just run the editor directly!


Addendum

This is a general principle: only run with the permissions strictly necessary. Judging from your other question, you've been running lots of things with sudo and friends. That's not a good habit to get into: the more things you use sudo with, the more things become owned by root and therefore require you to use sudo again. A vicious cycle. To set things straight again, you may want to set yourself as the owner:

sudo chown -R `whoami` path/to/directory

While you might not want to do this on system files, almost everything in your home directory should be owned by you. When the permissions are right, you should find you almost never have to use sudo.

icktoofay
  • 126,289
  • 21
  • 250
  • 231
  • Ok, the only reason why I used sudo or gksu is that I was unable to save anything I was working on. Based on your reply then the best course of action would be to set the privileges? – webdev Jan 02 '14 at 01:27
  • Or should I just move where the php files are being saved into the home folder along with sublime text 2? – webdev Jan 02 '14 at 01:34
  • @KansasCityShuffle: Either set the owner of the relevant directory to yourself or put the files in your home folder and configure your web server to serve the files from there, yes. You might want to keep the group as `www-data` (or whatever it is on your system) so you have write permission and Apache has read permission. – icktoofay Jan 02 '14 at 01:42
  • Yes, went ahead and set permissions instead of moving file directories around, many thanks on the explanation and tips. Cheers! – webdev Jan 02 '14 at 01:52
0

Never use sudo to start graphical applications as root, you run the risk of allowing the files in your ~HOME directory becoming owned by root.

Running gksu is almost identical to running sudo -i in which case the ~HOME environment variable is switched to root (hence the root/etc/etc)

Try using gksudo instead.

Emphacy
  • 79
  • 1
  • 7