8

I've tried three different ways to create a symbolic link to Sublime Text on my Mac and, after restarting terminal each time, it still keeps telling me command not found. I'm using a Mac with Yosemite (OSX Yosemite, 10.10). How can I create a symbolic link so I can open Sublime with the sub command?

One

ln -s 'Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl' /bin/sub

Two

ln -s "Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl" /bin/sub

Three (no quotes)

ln -s Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /bin/sub
  • does the link actually create something in /bin called sub? try sudo? – chris Mar 8 '15 at 1:20
  • 1
    If you use quotes, you do not want the backslash. If you don't use quotes, the backslash is necessary. You also need the leading slash on /Applications/…, as pointed out in the answer, and you need root privileges to write in /bin (hence sudo). The residual question is whether it is sufficient to run the executable like that. Are you sure you don't want a shell script that does something like open "/Applications/Sublime\ Text.app" instead as the contents of the file in /bin? – Jonathan Leffler Mar 8 '15 at 5:06
16

You're missing the '/' at the beginning of your app and sudo as /bin is owned by root and you can't actually write to it as a normal user. As you currently have it, it would only work if your present directory was the system root. This assumes of course that the Sublime Text app is in your main Applications folder.

Try this…

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

One afterthought: It's considered bad practice to change the content of /bin and /usr/bin because any upcoming OS X upgrade may wipe the content there. /usr/local/bin is the usual place to install user-provided binaries in, so

[[ -d /usr/local/bin ]] || sudo mkdir /usr/local/bin
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/sub

might be the better option.

Or (as you probably never need to run Sublime Text from within a shell script), simply define a bash alias

alias sub=/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl

which should be added to your bash startup file to make it stick

echo "alias sub=/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl" >> ~/.bashrc
  • 3
    You need to use sudo and if you are going to quote the pathname then don't use backslashes to escape spaces! – user3439894 Mar 8 '15 at 1:29
  • Don't forget single quotation marks around the path: alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl' Also better put that into ~/.bash_profile – drct Feb 8 at 18:25
0

Late to the party. I encountered the same issue when setting up my Mac and tried a few things. Here is what worked for me.

ln -sv "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

For more information, go to this github repo.

  • Aside from the fact that your command will fail, since you didn't use sudo and it's required in this case, how is this any different then what's already been offered within mockman's answer? Other then that fact that he choose to use sub vs. subl, so as to type one less character repeatedly to use it, it's really not from what I can see! – user3439894 Aug 25 '17 at 18:23
  • @user3439894 sudo is not a requirement. AND the command above uses /usr/local/bin not /usr/bin as the commands above. /usr/local/bin is the recommend directory for user applications whereas /usr/bin is used for distribution-managed user programs. So, sub vs subl is not the only change, it simply depends on user preference; what they want to write. I apologize if it causes confusion.. – L.T Aug 25 '17 at 19:54
  • 1. Running your command as is from an admin account, returns ln: /usr/local/bin/subl: Permission denied 2. I'd suggest you reread mockman"s answer as it absolutely has /usr/local/bin/ in the second sudo ln -s command in his answer! – user3439894 Aug 25 '17 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .