Problems using subl command in terminal: "Command not found" & "No such file or directory"

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!


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.


if you are using RVM, do this:

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

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

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


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 .