Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I launch Sublime Text 3 with sudo from my command line?

I just installed Sublime Text 3 on OS X Maverick, and it works fine.

I want to launch it from the command line, and I put a symbolic link to it like this:

 sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl \
            /usr/local/bin/subl

It worked. I can now do

$ subl <-- Launches Sublime Text 3 sucessfully
$ which subl
/usr/local/bin/subl

$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

But I can't do this:

$ sudo subl
Unable to find Sublime Text

I can't figure out why, because:

$ sudo which subl
/usr/local/bin/subl

sudo echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

Why can't I launch Sublime Text 3 with sudo from my command line?

like image 509
Bohr Avatar asked Oct 20 '22 22:10

Bohr


1 Answers

As you've now told me that:

$ sudo /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl

Successfully launches Sublime Text 3, then I would recommend using a shell alias, rather than symlink to make this more convenient.

Edit your ~/.bash_profile and add:

alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
alias sudosubl="sudo /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
like image 51
trojanfoe Avatar answered Oct 24 '22 00:10

trojanfoe