Sublime text 2 command create link but the command is empty

bashmacossublime-text-2

I want to create the link about sublime text2 which is placed in applications.

If I paste the /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl in bash, the sublime text 2 will open.

And I use the

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

and I check that my path has add the /usr/local/bin by echo $PATH which results in /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:

and I cd to the /usr/local/bin and found there is a subl script but I use vim to open it, the file is all blank.

And I restart the terminal and type subl but results -bash: subl: command not found.

How do I fixed it?

Best Answer

If you don't want to use Sublime Text 3 yet, which has a lot of differences from Sublime Text 2, and is still in beta, here's how to fix your problem. Just run each of these commands (in order) from Terminal and you should be all set:

sudo rm -rf /usr/local/bin/subl

This will remove whatever subl links are in /usr/local/bin. Then:

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

This recreates the link to the proper location. Make sure you run the command exactly as I typed it, or it won't work. I'll explain why in a moment. Finally, restart Terminal and enter:

subl

to make sure the process worked.


The reason your

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

command didn't work was because you included the Applications/... path in quotes " and also escaped the spaces using a backslash \. You should do one or the other, but not both. My command above just uses \ to escape the spaces. When you use quotes, each character in the string is included literally, including the \ characters. This is why the file was blank when you opened it in vim - it was pointing to a path that didn't exist.

By the way, while you can open /usr/local/bin/subl in vim, I wouldn't recommend it because it's a binary executable file, so you'll just get garbage on your screen.

Good luck!

Related Question