8

I installed a new code editor. Sublime 3. I want to be able to open Sublime from the command terminal so I can use commands like

Editor .

To open a code project whose directory I am in.

To do this I tried linking the Sublime App to my 'usr/local/bin' in the following ways.

ln -s /Applications/Sublime Text.app /usr/local/bin
ln -s /Applications/Sublime Text /usr/local/bin

'Sublime' now shows up in the '/usr/local/bin' directory, however the following commands don't work.

cd /path/code_folder
Sublime . 
Sublime Text.app . 
Sublime Text . 

They all return

-bash: Sublime: command not found
seamus
  • 2,681
  • 7
  • 26
  • 49

2 Answers2

9

You linked to the wrong thing. Sublime Text.app is really a directory, you want to symlink to the actual binary:

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

This is almost a verbatim copy/paste from the documentation. I kept the name subl though you could obviously easily use a different name.

Notice also the correct use of quotes; you created a symlink Text.app and another called Sublime, neither of which currently points to a valid location. See also When to wrap quotes around a shell variable?

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Symlinks are slightly pesky in that the system doesn't warn, or indeed check at all, whether the target exists when you create one. It wold be pretty pointless in any event, as the destination could go away at any time later anyway. But it's surprising and annoying when you first discover this. – tripleee Feb 16 '19 at 08:32
  • Tangentially, notice that you want the symlink in `/usr/local/bin`, not `/usr/bin`; the latter is reserved for the OS, and should not be tampered with. – tripleee Dec 20 '22 at 08:47
1

Download Sublime Text for Mac.

In your Downloads directory, double-click on Sublime Text.dmg to open it.

Drag Submlime Text 2.app into your Applications folder.

Run below command in your terminal.

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

Now open file in current directory using subl filename.

saikrishna
  • 11
  • 3