68

I'm having difficulty getting this set up. I fixed my .bash_profile, and created the symlink using the following command from the Sublime website:

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

Yet, when I input that command I get:

ln: /Users/my_username/bin/subl: No such file or directory

It appears my terminal is looking at the wrong place for the file? Why is it trying to point to a bin folder on my home directory?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
HectorOfTroy407
  • 1,737
  • 5
  • 21
  • 31

16 Answers16

175

Create the symlink in /usr/local/bin instead of ~/bin and make sure that /usr/local/bin in in PATH.

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

If you don't find /usr/local/bin/, then add the following lines to your .bashrc or .zshrc:

PATH=$PATH:/usr/local/bin/; export PATH
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Sarbbottam
  • 5,410
  • 4
  • 30
  • 41
  • So I have tried this, you can see the 'subl' in the /usr/local/bin yet the command still fails me. It exists in two places now however, the username/bin and the /usr/local/bin '~ :> cd /usr/local/bin bin [master] :> ls npm sub oid2name subl pg_archivecleanup vacuumdb pg_basebackup vacuumlo' I removed some of what was in there to not go over character limit. – HectorOfTroy407 Aug 06 '14 at 17:42
  • can you do a ``which subl`` and paste the output? – Sarbbottam Aug 06 '14 at 18:16
  • Thank you very much for helping I have managed to solve this issue! – HectorOfTroy407 Aug 07 '14 at 20:26
  • I just used the finder to locate the subl file and place it in my usr/local/bin, when i opened the contents of the app in finder i discovered the subl file was missing! i must've screwed it up somehow, so i deleted, reinstalled, and moved it over manually. – HectorOfTroy407 Aug 07 '14 at 20:27
  • 2
    for Sublime Text 2: ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/. – Wilhelm Dewald Dec 08 '14 at 22:50
  • It's ridiculous that a folder that's already on the PATH variable doesn't actually exist on my harddrive when the computer is shipped to me. – fIwJlxSzApHEZIl May 12 '15 at 19:22
70

This solved my Sublime terminal (subl) command issue after battling for a while on Yosemite:

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

Here is the source.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Babavalibob
  • 701
  • 5
  • 2
  • 1
    Me neither could get it going without su. Is there a reason for this? – Mauro2 Dec 26 '14 at 15:55
  • Just tried this (on Yosemite) but no luck. Even restarted terminal and checked my path.. – Christian Vermeulen Jan 12 '15 at 15:49
  • I'm getting this error: `sh-3.2# rm /usr/local/bin/subl` `rm: /usr/local/bin/subl: No such file or directory` `sh-3.2# ln -s "/Applications/Sublime` `Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl` `ln: /usr/local/bin/subl: No such file or directory` – fIwJlxSzApHEZIl May 12 '15 at 19:20
  • 1
    Steps to resolve for me: 1) `sudo su` 2) `cd /usr` 3) `mkdir local` 4) `cd local` 5) `mkdir bin` 6) `cd ~/` 7) run the sym link – fIwJlxSzApHEZIl May 12 '15 at 19:27
  • why do we need to use sudo su? – Roy Sep 18 '15 at 20:28
  • Thank you very much! I just had to change ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl to ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime – jamesscaggs May 06 '16 at 19:04
  • I've added sym link without quotes, this fixed it – Haris Krajina Oct 07 '16 at 11:54
13

"Launch Sublime Text from the command line on OSX" worked for me. I use Sublime Text 3 and only had to copy and paste the commands below to the command-line. I did this at the root level

$ cd ~
  • If you're using Sublime Text 3 copy then paste this to the command line:

    // Sublime Text 3
    $ ln -sv "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
    
  • If you're using Sublime Text 2 copy then paste this to the command line:

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

Now test it out to see if it works:

  1. Open a new file from the command line:

    $  subl test.rb  // it should open new file test.rb in Sublime Text
    
  2. Open a project folder:

    $ subl dir/myProject // opens a new folder inside Sublime
    
  3. Launch Sublime app:

    $ subl // launches Sublime
    

To open Sublime Help for more detailed options use:

$ subl -h // Sublime help
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
12

You could just add the following to the shell config file .bash_profile or .zshrc (Apple replaced bash with zsh as the default shell in macOS Catalina):

alias subl="open -a /Applications/Sublime\ Text.app" 

These are the steps to edit .zshrc and save the changes (press ESC and :wq! to save and exit):

$ cd ~
$ vim .zshrc
$ source .zshrc

To verify that it works, try the following and it should open up Sublime Text.

$ subl .zshrc
Dorjee Dhondup
  • 549
  • 6
  • 15
8

If you are using Sublime Text 2 try this:

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

or, if your path is in /usr/bin/ instead /usr/local/bin:

$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
CristianP
  • 127
  • 1
  • 6
6

My similar problem was solved simply by omitting the quotes. So if you're working with:

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

I instead did:

ln -s /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl ~/bin/subl
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Eric Levine
  • 63
  • 1
  • 3
  • Can confirm that this worked for me too. I tried the former first but didn't work. The latter did though. Thanks! – Chris Feb 27 '17 at 09:36
3

While sarbottam's answer is the proper way to do it, if you're lazy like me, and use subl to just do an subl ., you can add an alias to your ~/.bash_profile

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

and either open a new terminal window or run the .bash_profile

3

For Sublime Text 4 and Monterey:

ln -sfv /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
Abel
  • 3,989
  • 32
  • 31
3

I am using MAC m1 chip. None of the answer above worked for me. But I find this one worked.

alias subl="open -a /Applications/Sublime\ Text.app"

# IN CLI
$ cd ~
$ vim .zshrc
$ source .zshrc
$ subl .
# Now it should work! Try restarting the terminal as well if you need to!

Source: https://www.codegrepper.com/code-examples/shell/subl+command+not+found+mac

1

At my end subl was working fine but git was unable to access it. And was displaying these errors

subl -n -w: subl: command not found
error: There was a problem with the editor 'subl -n -w'.

For Mac OS X in the file ~/.gitconfig under [core] I had to put this code to solve the issue on my end.

editor = /Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl  -n -w
Ahmad Awais
  • 33,440
  • 5
  • 74
  • 56
1

I tried several combinations using sudo and also including or excluding leading / and escaping spaces in the Sublime\ Text.app package.

What worked to create the desired symlink was:

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

I did not have to use sudo or modify $PATH.

For reference, I am on Mac OS Mojave 10.14.

echo $PATH currently (and without any modification by me) shows the following:

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

You can tell if this worked by typing which subl immediately after running the ln command above. If you don't get a line of output showing you where Bash found your subl command then you don't have it.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
1

This is what worked for me.

First, make sure you are in home folder:

cd ~

Step 1: Remove the /Users/Ram/bin/subl directory by using following command line:

rm -rf /Users/Ram/bin/subl

Step 2: Create this folder again using following command line:

mkdir /Users/Ram/bin/subl

STEP 3: use the following command to create a symbolic link to sublime:

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

(using sudo before this command overrides permission issues)

Step 4: Now you can test if subl works:

subl test.py

This should open up sublime with new test.py file created.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
0

I'm documenting this because it worked on my machine and might fix the problem for people who see "file already exists` when they run the command suggested in sarbbottam's answer. I'm not sure I can fully explain it so I may use the wrong terms.

When I copy/pasted sarbbottam's command, my terminal reported that the file already existed. I tried copy/pasting several Stack Overflow answers to this problem into my terminal, so I had symlinks called subl and sublime in my /usr/local/bin directory. I could see the file when I listed all files in that directory with ls -a. I tried to open the subl directory in a text editor, and it said that the file didn't exist.

I deleted the subl symlink in /usr/local/bin, ran the command, and it worked.

I think I accidentally made one for Sublime Text 2 or something, and just figured I'd be overwriting the last one which was not the case.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
brendan_d
  • 1
  • 1
0

There might be an issue with having multiple symbolic links to the same target. I removed my link "subl" and my link "sublime" still works.

Puneet Lamba
  • 755
  • 8
  • 15
0

I just downloaded MacOS Catalina version10.15 on a new iMac and following the Sublime documentation found that the following with double quote does not work for me:

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

I instead did:

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

and it worked.

ATTENTION: this is the code worked on my iMac - MacOS Catalina 10.15, and I copy/pasted the working line directly from my machine. If you find other code working, please add another answer and specify your machine configuration. Or simple comment below. DO NOT EDIT THE CODE SECTION, ESPECIALLY ADDING THE DOUBLE QUOTE FOR THE WORKING LINE. THANKS!!

sylvia
  • 283
  • 3
  • 11
  • People: Please do NOT edit code section for this answer, as this is the code worked on my iMac - MacOS Catalina 10.15, and I copy/pasted directly from there. If you find other code working, please add another answer and specify your machine configuration. – sylvia Nov 25 '19 at 18:24
0

If you've received the No such file or directory error on the M1 or ARM64 Apple architecture:

  1. Make sure your copy of Sublime Text.app is in the /Applications directory.

  2. If you hate Vim, you may make edits to your zshrc file with Nano, instead:

    nano ~/.zshrc

  3. Within the resulting editor, you may add the following line:

    alias subl="open -a /Applications/Sublime\ Text.app"

  4. Then simply press ctrl+x key to exit the interface.

  5. You will be prompted inline to save the changes. Press Y to retain the edits.

  6. Write source.zshrc and then press return.

  7. Finally, you can write subl .zshrc and then press return.

This should result in seeing the contents of .zshrc right within Sublime Text.

Ron Kagan
  • 23
  • 7