Permission denied when trying to make sublime text shortcut

7.4k Views Asked by At

So I just started getting into using terminal to manage files etc, and I was trying to setup my sublime text shortcut using this line of code:

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

However, when I try to do this it says Permission Denied and I have no idea why. I am using a Mac running Mac 10.10.2.

4

There are 4 best solutions below

1
On

If you are on Mac, I would suggest creating a file /usr/local/bin/sublime or somewhere else on your PATH and putting open -a Sublime\ Text $@ inside instead of creating a link. open -a tells Mac to open an application that is in your /Applications/ directory. and the $@ symbol passes on any additional arguments that you supply to the script. Thus, you can open a file by doing sublime file.ext. That said, it is possible that your permission denial is that you don't have permission for the /usr/local/bin directory. If that is the case, you need to change the permission using chmod, or just put the script somewhere else like ~/bin

3
On

If you look at the permissions on /usr/local/bin you will see it is owned by root:

$ cd /usr/local
$ ls -l .
total 0
drwxr-xr-x@ 8 root  wheel  272 Apr 16 11:31 bin
drwxr-xr-x  3 root  wheel  102 Apr 16 10:02 include
drwxr-xr-x@ 3 root  wheel  102 Apr 16 10:19 share

Therefore you need to use sudo to gain super user privileges. You will need to enter your user account password and you will need to be an Admin user (see System Preferences > Users & Groups):

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

Note that you don't need the trailing subl on the destination as ln will figure that out itself.

0
On

For sublime text 3:

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

0
On

In addition, if you're using Sublime Text 3, this is the correct command for the symlink:

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