56

I'm trying to set-up Sublime Text 3 on OS X Mavericks and getting levels of frustration.

I've followed all of the usual suspects in regards to installation and setup, i.e. Googling the Sublime Text website, and Stack Overflow. Inevitably it's something minor I'm missing, but it's causing me major heartburn.

What I've done so far:

  1. Downloaded Sublime Text 3, sitting in my /Applications directory
  2. Followed the guide Launch Sublime Text 2 from Mac Terminal

The problems starts here. I know that the symlink presented in this link is using ST2, but I want to use "sublime" instead of the "subl"(personal preference). I searched around and found what I need to paste into Terminal for ST3:

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/usr/local/bin/sublime
  1. Already had a ~/.bash_profile: export PATH=/usr/local/bin:$PATH. However, when I echo $PATH I get:

    /usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
    

    Does this look correct?

  2. Now when I type sublime into the terminal I get command not found

What am I missing. This is driving me crazy as I fell that I have followed all the steps, but ST3 is still not working for me

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Zoop
  • 693
  • 1
  • 6
  • 6
  • 1
    Are you sure it's ``~/usr/local/bin/sublime`` and not ``/usr/local/bin/sublime``? – fjarri Oct 23 '13 at 13:56
  • @Bogdan: I tried removing ~, and the quotation marks in front of /Application and the quotation marks after subl (reference my original question), but now I get `ln: /usr/local/bin/sublime: No such file or directory`. But when I cd to `/usr/local/bin/` I can see sublime listed. Any ideas? – Zoop Oct 23 '13 at 15:23
  • This looks like a general computing question, not a programming-related question. – trojanfoe Oct 23 '13 at 15:53
  • 2
    @trojanfoe it's a practical, answerable question about a software tool commonly used by programmers, seems pretty reasonable to me http://stackoverflow.com/help/on-topic – Joe Taylor Jan 21 '14 at 11:05

7 Answers7

128

Should be:

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

Notice I removed the tilde (~). Tilde (~) in Unix refers to your user's home directory, so your source was correct, but the second argument was placing the link in /Users/[your username]/usr/local/bin/ which is not included in $PATH.

In your note, you said you tried removing the quotes from the source argument. If you remove the quotes, you need to be sure to escape the space character as follows:

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

That should work as well.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Mike
  • 1,402
  • 1
  • 11
  • 11
  • I copy/pasted your first bit of code into terminal. Terminal returns `ln: /usr/local/bin/sublime: File exists'. When i type in `sublime` into terminal I still get `command not found`. This is the source of my confusion/frustration. – Zoop Oct 23 '13 at 16:08
  • 3
    @Zoop, you most likely created `/usr/local/bin/sublime` when you ran the `ln` command without the ~. Try `ls -l /usr/local/bin/sublime` and you'll see something like: `/usr/local/bin/subl -> /Applications/Sublime `. If so, `rm /usr/local/bin/sublime` and then run the `ln` command I provided again. – Mike Oct 23 '13 at 17:07
  • FIXED. Thanks man, I was pulling my hair out. I'm not sure what I did that screwed things up, but everything is fixed. I run sublime in terminal and ST3 window pops up ready to go to work. Thanks for the help - have a good one! – Zoop Oct 23 '13 at 17:23
  • Prefered this method and it worked for me. Using /usr/local/bin folder seems to be the best idea. – Sinan Eldem Sep 22 '14 at 13:34
  • 1
    To everyone being slightly confused why they get the error `command not found: subl`, the author (and the op) ask for linking `sublime` rather than `subl` (the latter is common and used on sublime's homepage) – Lukas Jun 17 '15 at 18:29
14

Mavericks does not ship with a ~/bin directory, but found I ran into trouble trying to install the subl command in any of the low-level system bin directories. I found the following solution worked neatly:

Create a ~/bin directory for your user:

mkdir ~/bin

Add the subl command as per the Sublime Text documentation:

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

Open /etc/paths in your (second) favourite text editor:

sudo vi /etc/paths

Add the active user's ~/bin folder. Here's how mine looked after I'd added ~/bin:

~/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Orangetronic
  • 300
  • 5
  • 10
10

Rather than having cumbersome sudo links to setup I prefer to use a simple bash function and use the native Mac open command:

#somewhere in your .bashrc or .zshrc
sublime () {
    open -a "Sublime Text" $@
}

Now all you have to do is sublime . whenever you want to open up sublime from a given folder. Obviously you can simply rename it subl.

Note The name to write in the -a parameter is the name of the application as stored in the the /Applications folder:

enter image description here

apouche
  • 9,703
  • 6
  • 40
  • 45
  • Nice, thanks. How to open not a new sublime but in new sublime tab if a sublime instance is open already. – Narek Nov 17 '15 at 05:31
8

After a few days of struggling with the issue, this worked for me.

Make sure you have ~/usr/bin set in $PATH

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

If you get a permission denied error:

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

Type in your password.

Bebop_
  • 645
  • 2
  • 6
  • 9
1

This works for me as well:

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

Than you can write just:

st filename.file extension

It should works. I tried so many things but this worked first.

Hexaholic
  • 3,299
  • 7
  • 30
  • 39
0

The answers already given are all fine but what about making your life waaay easier and rely on good tools instead ;)

  1. Install 'Oh My ZSh' (imho: a must have) https://github.com/robbyrussell/oh-my-zsh
  2. Open the configuration file: ~/.zshrc
  3. Add sublime to the plugins: plugins=(sublime) (other recommendations: brew colored-man git osx)
  4. Open your terminal on steroids and type: st foo.txt
  5. Giggle in bliss and read the other cool stuff 'Oh My ZSh' can do for you!
Lukas N.P. Egger
  • 923
  • 2
  • 9
  • 12
0

If you want to run Sublime from the terminal, append the following to your ~/.bash_profile file (~/.zshrc in case you use zsh).

subl () { open -n -b "com.sublimetext.3" --args $* ;}

Now, you can simply type subl . in any folder to start editing files in that folder.

mrded
  • 4,674
  • 2
  • 34
  • 36