Solution for ‘sudo subl’ – “cannot find sublime” error… with Sublime Text 3 on OSX 10.11.5

If you use Sublime Text 3 as your editor on OSX (like myself) and you have created a symbolic link to launch sublime from your terminal, but you have noticed that when attempting to launch Sublime Text 3 with super user privileges by typing sudo subl file_name_here and your terminal outputs ‘Unable to find Sublime Text’…

The problem seems to be that the symbolic link ‘subl’ script is attempting to look for Sublime Text at the following path /Applications/Sublime\ Text\… However when you download & install Sublime Text 3 on OSX into the usual /Applications/ directory, the path to┬áSublime Text 3 will just be as follows /Applications/Sublime\… This is why you are seeing the ‘Unable to find Sublime Text’ message when running sudo subl.

In order to fix this, you must firstly delete the symbolic link you have created at ‘usr/local/bin/subl’. To do this run the following command in your terminal:

cd /usr/local/bin; rm subl;

Next rename┬áSublime Text 3 to ‘Sublime Text 3’ in your Applications directory. (It will probably be named ‘Sublime Text’ at the moment.) Do this by running the following command:

mv /Applications/Sublime\ /Applications/Sublime\ Text\;

Next you can follow the normal procedure of creating the symbolic link to the script provided by Sublime Text 3, by running the following command in your terminal:

ln -s /Applications/Sublime\ Text\ /usr/local/bin/subl

Hope this is clear and that it helps!