Search code examples
environment-variablesosx-mavericks

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?


Solution

  • 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"