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

BashTerminalSublimetext2

Bash Problem Overview


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!

Bash Solutions


Solution 1 - Bash

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.

Solution 2 - Bash

if you are using RVM, do this:

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

Solution 3 - Bash

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

Solution 4 - Bash

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

Solution 5 - Bash

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 .

Solution 6 - Bash

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

Solution 7 - Bash

You can also create new alias if you want like

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

Solution 8 - Bash

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

$ subl . This works! :D

Solution 9 - Bash

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.

Solution 10 - Bash

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

Solution 11 - Bash

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

Solution 12 - Bash

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.

Solution 13 - Bash

In linux sublime 3, in your terminal paste

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

Then

subl3 [filename]

Solution 14 - Bash

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRalitzaView Question on Stackoverflow
Solution 1 - BashisanjosgonView Answer on Stackoverflow
Solution 2 - BashBob WalshView Answer on Stackoverflow
Solution 3 - BashRahul AroraView Answer on Stackoverflow
Solution 4 - BashRimianView Answer on Stackoverflow
Solution 5 - BashNaguib IhabView Answer on Stackoverflow
Solution 6 - BashnuinView Answer on Stackoverflow
Solution 7 - BashPankaj AgrawalView Answer on Stackoverflow
Solution 8 - BashRajView Answer on Stackoverflow
Solution 9 - BashJeremyView Answer on Stackoverflow
Solution 10 - BashSean CrockettView Answer on Stackoverflow
Solution 11 - BashPeter HastieView Answer on Stackoverflow
Solution 12 - BashitachiluanView Answer on Stackoverflow
Solution 13 - BashVimm RanaView Answer on Stackoverflow
Solution 14 - BashLokesh PurohitView Answer on Stackoverflow