58

I want to apologize in advance that this is a newbie question! I've spent the last 2 hours trying to find a solution.

I have two problems (I'm sure related).

Background:

This is what my $PATH looks like:

/Users/Sponsi/.rvm/gems/ruby-1.9.3-p194/bin:/Users/Sponsi/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/Sponsi/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/Sponsi/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin

Problem #1

I am trying to use the command-line command "subl" to launch Sublime Text 2 on OSX.

I entered the following command: "ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

It only halfway worked - when I enter "subl" I get "Command not found". But when I re-enter the command above it says "Already exists."

I searched online and found a (somewhat) fix. I added the following to my .bashrc:

echo 'export PATH="./bin:$PATH"' >> ~/.bashrc 
source ~/.bashrc

Using the command "subl" does work but only temporarily. If I exit terminal or switch to another directory it stops working (bringing me into problem #2, see below.)

Problem # 2:

When I try to pull up a file under another directory using the command "subl" I get "-bash: ./bin/subl: No such file or directory" I confirmed the file I want to edit does exist.

BTW, I am following the Ruby tutorial found @ http://ruby.railstutorial.org/ruby-on-rails-tutorial-book

Thank you so much for your time!

14 Answers 14

157

Run each command in the Terminal (in this order):

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

This should work!

Note: First you should check that your sublime's app is in Applications folder and it's name is Sublime Text 2, if not, you should change the name in the second command and type the name of sublime's app.

4
  • only thing that seemed to work for me for some reason.
    – Josh Bedo
    Mar 4, 2014 at 22:43
  • this was the one for me. Thanks!
    – Uri Klar
    Nov 25, 2014 at 9:45
  • Note added above helped me. Mar 12, 2016 at 9:46
  • 1
    amazing, work on me 192:~ radityagumay$ cd 192:~ radityagumay$ sudo rm -rf /usr/local/bin/subl 192:~ radityagumay$ sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin 192:~ radityagumay$ subl . Oct 15, 2017 at 6:47
94

if you are using RVM, do this:

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/.rvm/bin/subl
2
  • Works perfectly, must be something with rvm messing with the path.
    – Matt Smith
    Oct 30, 2013 at 3:48
  • Worked like a charm. Thank you, Bob.
    – Alex Pan
    Oct 23, 2015 at 6:54
34

For El Captain or later OS:

In El Capitan, you are not allowed to write to /usr/bin, but writing to /usr/local/bin is ok. By default, /usr/local/bin should also be in your path variable.

For Sublime Text 3

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

For Sublime Text 2

sudo rm /usr/local/bin/subl
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
1
  • 1
    I've had trouble with this all day, this was the only thing thats worked. thank you!
    – Gil
    Oct 27, 2019 at 1:30
25

I stuck mine in /usr/bin

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

or for Sublime 3 or later

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

It's already in $PATH

5
  • 2
    This is the best way to go if you have /usr/bin already. Picks it up automatically without any other fidgeting. Mar 7, 2013 at 18:19
  • 5
    For Sublime Text 3 (and later) just leave off the "\ 2". Like this: sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin
    – Stan James
    Aug 16, 2013 at 15:27
  • 2
    I get operation not permitted when I do this. Any ideas? May 6, 2016 at 18:43
  • Could be a permissions thing or a corrupt file. Hard to know.
    – Rimian
    May 7, 2016 at 0:01
  • 2
    Per this answer, it has to do with El Capitan's new System Integrity Protection feature. I was running into the same issue, and changing the location of the link to /usr/local/bin solved the problem for me.
    – Brice
    Oct 23, 2017 at 17:57
13

If you're using Sublime Text 3 you need to adjust the commands in isanjosgon's answer:

$ sudo rm -rf /usr/local/bin/subl
$ sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/
$ subl .
7

I had the same problem, on a new Mac recently configured. I had RVM installed before oh-my-zsh and sublime text and I was running into the same problems. I tried different locations on the path

/usr/bin
/usr/local/bin

all of them in the path. What worked for me was to get rid of the quotes on the command line running as

sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/bin/subl
2
  • 1
    This is what fixed it for me too. May 27, 2014 at 0:24
  • The Sublime Text documentation sublimetext.com/docs/2/osx_command_line.html has quotes around the /Applications.... path. You are quite right that leaving the quotes off is the solution. To see your path type 'echo $PATH'. /usr/local/bin is the best place to put the symlink and should already be in your path. Jan 21, 2015 at 18:06
4
$ alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"

$ subl . This works! :D

3

You can also create new alias if you want like

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

2

Edit your ~/.bashrc file to contain this line at the end of it:

export PATH="$HOME/bin:$PATH

Notice the ~ is there instead of the . from your example? The ~ signifies your home directory, which is where your .bashrc file lives. The dot signifies the current directory of your terminal window.

Once you've made the change, close your terminal window and re-open it. Then subl should be avaiable on the PATH.

2
  • 1
    I'm confused. Now, all I'm receiving is "Command not found". I've restarted my computer, reinstalled Sublime Text, deleted and re-added the subl file in my /bin, and reentered all the commands above to no avail. The only change I did to my computer was delete a user account - that shouldn't have anything to do with subl not working, right?
    – Ralitza
    Jun 8, 2012 at 19:54
  • Perhaps use export PATH="$HOME/bin:$PATH instead? I probably should have said that in the first place. You shouldn't have to delete your program and re-install it. This is purely a configuration issue external from the program itself.
    – Jeremy
    Jun 8, 2012 at 19:57
2

Regarding your first problem, could it be that you don't have a bin directory set up under you home directory (i.e., ~/bin)? To check this, type the following:

cd ~/
ls -l

If there is no bin directory, type the following:

mkdir bin

Once you've created the directory, retype the following:

subl --help

Hopefully that takes care of the issue

1

There's a slight change to the path from that in the accepted answer following an update to Sublime Text.

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

0
0

The reason that when you changed directory or re-opened terminal then the PATH wouldn't work is that .bashrc is a non-login interactive file.

Simply use this line in terminal:

echo 'export PATH=$PATH:~/bin' >> ~/.bash_profile

will probably solve the problem since .bash_profile is loaded every time there is a login.

if you don't have .bash_profile, just before using the above command, type this in Terminal:

cd ~
touch .bash_profile

then use the formal command.

I would not touch usr/local/bin usually since it is a system level folder. Heard that recently in OS X El Capitan, Apple made some permission restrictions. So just put the clone in your home directory under /bin folder and adding the PATH in your .bash_profile, everything should then be working.

0

In linux sublime 3, in your terminal paste

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

Then

subl3 [filename]
0

I first checked the which subl returned nothing. That meant have to add path of subl to PATH variable required.

So adding to PATH variable path of subl helped

PATH=$PATH:/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/

You may first want to find correct path of your subl and add that to PATH variable

If that works, add the path permanently by adding below command to your .bash_profle

export PATH=$PATH:/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/

Note: path to subl may differ in your system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.