Permission denied when trying to make sublime text shortcut

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 17:09:19

问题


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.


回答1:


For sublime text 3:

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




回答2:


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.




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/30762603/permission-denied-when-trying-to-make-sublime-text-shortcut

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!