9

Original Sublime 2 instruction for enabling editor to launch from command line:

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

do not work in Mountain Lion.

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Pavel Binar
  • 2,096
  • 5
  • 16
  • 26

4 Answers4

21

Create the ~/bin directory if it doesn't already exist:

mkdir ~/bin

Then run the ln again. Make sure that directory is added to your $PATH by adding this to the ~/.bashrc file, creating it if it doesn't exist:

export PATH="$PATH:~/bin"

If you don't use bash, use your manual to figure out how to add a directory to your $PATH variable.

This is actually what the instructions say:

The first task is to make a symlink to subl. Assuming you've placed Sublime Text 2 in the Applications folder, and that you have a ~/bin directory in your path, you can run: [snip]

This implies you need to create the ~/bin directory if it doesn't exist, and add it to your $PATH if it is not there already. The above instructions do exactly that.

If you don't like that ugly bin folder in your pretty home folder, you can use chflags to make it disappear from the Finder:

chflags hidden ~/bin
zneak
  • 134,922
  • 42
  • 253
  • 328
  • This worked perfectly for me, but every time I close and reopen my terminal, I am forced to re-input export PATH="$PATH:~/bin", any idea how to make this stick? Thanks! – jackerman09 Sep 26 '13 at 21:08
  • Yes. It seems you missed step 2 about the `.bashrc` file. – zneak Sep 26 '13 at 23:35
  • my bin folder is within Users/myname/bin. It contains subl. How can I make it so that this is used? – jackerman09 Oct 09 '13 at 17:46
  • 2
    ~ means "your home folder", so ~/.bashrc means "the file called .bashrc inside /Users/myname". Create that file, and put the `export PATH="$PATH:~/bin"` line in it. The changes will apply to every subsequent terminal window. – zneak Oct 09 '13 at 18:14
11

Change target directory to system folder /usr/bin and use sudo for admin rights.

sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /bin/subl
Pavel Binar
  • 2,096
  • 5
  • 16
  • 26
  • 3
    This works only because in OSX /bin is already on $PATH and ~/bin by default is not. – om-nom-nom Dec 01 '12 at 01:14
  • Don't add stuff to `/bin`. `/bin` should be reserved for built-in executables. `/usr/bin` is the right place for non-system executables available for all users (and `~/bin` is the right place for non-system executables available for just you). – zneak Dec 01 '12 at 01:16
  • 1
    OK, thanks! I found an solution that works, but was not right conceptually. Good to know. – Pavel Binar Dec 01 '12 at 22:55
4

I recently ran into this problem on OSX Mountain Lion and then again on Mavericks. This solution worked for me:

Create the bin directory in /usr/local/bin if it doesn't already exist:

sudo mkdir /usr/local/bin

You have to use sudo and enter your password to create the directory because it is inside a system folder.

Setup subl as a command-line command in the /usr/local/bin:

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

The directory /usr/local/bin is already in your $PATH by default, even if it doesn't exist yet, so there is no need to add it to your $PATH. The folder /usr/local is also the folder used for git and homebrew installs, so it makes sense to keep all your local command-line commands in this location.

Maalur
  • 41
  • 3
0

Maybe its already here, but this one worked like a charm for me:

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
Vincent van Leeuwen
  • 681
  • 1
  • 9
  • 17