Bash – Problems using subl command in terminal: “Command not found” & “No such file or directory”

bashsublimetext2terminal

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!

Best Answer

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.

Related Topic