Open Sublime Text from Terminal in macOS
Solution 1
I finally got this to work on my OSX box. I used these steps to get it to work:
-
Test
subl
from your ST installation:First, navigate to a small folder in Terminal that you want ST to open and enter the following command:
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl .
NOTE: You may need to replace
Sublime\ Text.app
in the command above toSublime\ Text\ 3.app
orSublime\ Text\ 2.app
depending upon where the application is stored in yourApplications
directory. The.
at the end of the above command opens the current working directory you are located in (again make sure you're in a directory that only contains a few files!).If you DO NOT get Sublime Text opening your current working directory then the next set of steps will NOT work. If nothing happens or you get an error from Terminal it will be because it couldn't find the Sublime Text application. This would mean that you would have to check what you've typed (spelling, etc.) OR that Sublime Text isn't installed!
-
Check ".bash_profile":
Now it's time to create your symbolic link in your
PATH
folder, BUT, before we do, let's check your profile file by usingnano ~/.bash_profile
. These are the following lines that pertain to havingsubl
work on the command line for Sublime Text:export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH export EDITOR='subl -w'
The first line sets the location where you want Terminal to look for binaries on your machine, I'm going to store my symbolic link in the
/usr/local/bin
directory - I guess you could store it anywhere provided you've notified Terminal where to look for binaries.The second line is OPTIONAL and just sets Sublime Text as the default editor. The flag
-w
has been added and you can find out more about flags by going to the Sublime Text docs: ST4 subl, ST3 subl or ST2 sublIf you do make any edits to this file once you have closed it, you need to run the command:
source ~/.bash_profile
to compile your newly applied edits. If you see any errors after sourcing your file get them fixed before moving to the final step.
-
Create a symbolic link to Sublime Text:
Now in your chosen path (I used
/usr/local/bin
) you now enter the following command:ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
The
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl
being EXACTLY the same location as what you entered and verified as working in STEP 1 above. The/usr/local/bin/subl
being the location of where you want the symbolic link to be located - needs to be one of yourPATH
locations from STEP 2 above.Now when you navigate to a folder or file that you want to open in Sublime Text you now just enter
subl
followed by the name of the file or.
to open the current working directory.
Solution 2
For MAC 10.8+:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
worked.
Solution 3
Assuming:
- You have already installed Homebrew.
- /usr/local/bin is in your $PATH.
- You are on Yosemite or El Capitain.
MacOS Sierra 10.12.5 works as well confirmed by David Rawson and MacOS Sierra 10.12.6 confirmed by Alexander K.
Run the following script in Terminal to create the specific symlink.
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Then:
subl .
Hit Return and it should instantly open Sublime Text.
Solution 4
I'm using oh-my-zsh on Mac OSX Mavericks and the symbol link didn't work for me, so I added an alias in my .zshrc file instead:
alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
Open a new terminal and you should be good to go, and type subl
.
Solution 5
This worked for me (I'm using OS X Mavericks)
First, create a symbolic link:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin/subl
Now you can open sublime with
subl "/a/path/to/the/directory/you/want/to/open"

user1405049
Updated on July 08, 2022Comments
-
user1405049 6 months
In Terminal when I use
.subl
It returns
-bash: .subl: command not found
Anyone know how to open Sublime Text 3 from the command line in macOS?
-
user1405049 over 9 yearsIt returns
ln: /Users/###/bin/subl: No such file or directory
-
danmanstx over 9 yearsdid you look at the link at the bottom of my answer? try to following command
ln -s "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl" ~/bin/subl
-
rs77 over 9 years@danmanstx I've created the symbolic link in my
/usr/local/bin
directory yet it still gives me the error. I note that my ST3 package has been installed at/Applications/Sublime Text.app/...
and have made the distinction when creating my symbolic link. Yet the error remains - I think it has something to do with my.bash_profile
file. -
Richard Ortega over 9 yearsI had a problem with ST3 where when I first typed in
subl .
I would get a Sublime editor calleduntitled
and it didn't reference any files in the directory I was in. Doingexport EDITOR='subl -w'
to my.bash_profile
fixed this. -
Giles Butler about 9 yearsThis worked for me but I had to remove the symlink to the old subl file first.
-
dnlcrl about 9 yearsI had to sudo rm /usr/bin/subl to make it work on OSX 10.9, thanks!
-
stevenspiel about 9 yearsthis worked beautifully until the last step. I'm getting
ln: /usr/subl: Permission denied
Thoughts? -
stevenspiel about 9 yearsI think I found the answer here stackoverflow.com/questions/10196449/…
-
merqlove about 9 yearsSame here, but for Bash.
-
Ben Haley almost 9 yearsI had to use the home directory, ~, instead of /usr/bin, to make this work for me ... "sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl ~/bin/subl"
-
Roy Calderon over 8 yearsThx Michael Keenan, worked great with Sublime Text 3 on Mavericks!
-
Bruno Koga over 8 yearsWorked on Sublime 3 running on Lion (10.7.3) :)
-
Joshua Soileau over 8 yearsSame here, this worked for me, but I needed to change it to Sublime text 2 with this string: "Sublime\ Text\ 2.app/"
-
Jitendra Vyas about 8 yearsThis is working but it's not opening the same folded where I ran Subl
-
Sarah Lewis about 8 yearsAs @mr.musicman found, you may need to use
sudo
in front of the command in step 3. -
A F about 8 yearsIf you get
/usr/local/bin/subl: No such file or directory
runmkdir /usr/local/bin
. Your machine is telling you that the/usr/local/bin
folder does not exist, so you can't write to it. -
Reb almost 8 yearsWorked on Sublime 2 (with variations as per your note, and using sudo before the command as Sarah points out) on Snow Leopard. Thanks!
-
Christian Gossain almost 8 yearsPerfect! This answer did it for me. Thanks!
-
atilkan almost 8 yearsThis is for ST 2 i guess. ST 3 comes with CLI but i can't run it yet.
-
Montaro over 7 yearsFor sublime2
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/bin/subl
-
tmthyjames over 7 yearsAfter trying the other answers, this one was the only one to work for me. Mac OS X Yosemite 10.10.1.
-
Admin over 7 yearsOne thing that I ran into was I needed to create a bash profile (with: touch ~/.bash_profile). I also did not have a usr/local/bin so I choose usr/local/sbin as the directory (which is the same as bin but requires sudo privileges). If you have permission errors, you should run the command 'sudo' first.
-
mbokil over 7 yearsIf you faster access you can create an alias. Type nano .bash_profile and paste in: alias subl="open -a 'sublime text'"
-
Kuchi over 7 yearsWorked on OS X 10.10.4
-
Thomas Bindzus about 7 years@emrah I am using ST3
-
atilkan about 7 years@ThomasBindzus I figured out later. Thanks.
-
Ganatra about 7 years@Tinple I am sorry I haven't tried it on 10.11, I guess the same thing should work
-
Ross about 7 years@Tinple This works in 10.11
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
See the answer here for why - apple.stackexchange.com/questions/196224/… -
Dennis Golomazov almost 7 yearsThank you! It's the only solution that worked for me. To make it open in a new tab in the existing window (not in a new one), see stackoverflow.com/questions/9961350/…
-
pjlamb12 over 6 yearsThe big step for me here was the PATH setup. I think my path was off, and that was keeping my symlink from working.
-
Vinodh Thiagarajan over 6 yearsI'm new to Mac and I tried for quite sometime to make it work. Let me tell the reason why other straight forward answers didnt work. While installing Sublime Text for the first time , remember it will ask "Just for you or everyone" , so it is installed in the Applications folder found in your ROOT. Even though it will show under your Applications. Hence this SUDO (Super user Do , played a vital role). First thing Im learning UNIX/LINUX whatever. Wanted to share this learning.
-
CodeBiker over 6 yearsThis did not work for me on Mac OS X El Capitan -- I was unable to copy to file over. Chutipong Roobklom's answer did work, however.
-
Telvin Nguyen over 6 yearsWorked on OSX 10.11.4
-
Michael Conlin over 6 yearsWorked for me on two separate macs. I appreciate the well written explanation.
-
MageeWorld over 6 yearsMaybe not everyone knows this - but if you set up the subl link for sublime text 2 (as I did) you either need to remove the existing symbolic link (if you're a mac user like me you know enough to be dangerous but not it all)(
-
Robert Sinclair over 6 yearsthe only thing that worked after following the instructions, super thorough! Better than the blogpost or the git post I had to waste time on before landing here
-
NicolasKittsteiner over 6 yearsIn my case the link points to
ln -s /Volumes/Macintosh\ HD/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl
-
Subhajit about 6 years@ChutipongRoobklom Thanks. It worked for me on
macOS Sierra Version: 10.12 (16A323)
. -
organillero about 6 yearsln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
-
vgrinko about 6 yearswhy do we need quotes? it works with quotes for me, but does not work without them?
-
Ken Ratanachai S. about 6 yearsln: /usr/bin/subl: Operation not permitted
-
Josh Foskett almost 6 years@KenRatanachaiS. Use
/usr/local/bin/subl
, instead of/usr/bin/subl
. -
Angelfirenze almost 6 yearsThis finally did it, thank you so much for posting this! I've been trying to get ST3 to run from the command line for months after the original symlink broke for some reason. Anyway, thank you!
-
Code Cooker over 5 yearsHere is a useful video it will solve your problem to adding sublime with cmd or git bash Open sublime with git or CMD
-
David Rawson over 5 yearsWorking on macOS Sierra 10.12.5. Thanks
-
Alexander Kucheryuk over 5 yearsCan confirm that works on macOS Sierra 10.12.6 as well. Thank you!
-
talsibony over 5 yearsmy sublime text path was different I guess it because I am using sublime 2 ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
-
talsibony over 5 yearsAll you had to do is uncoment the export PATH=$HOME/bin:/usr/local/bin:$PATH in .zshrc and then source ~/.zshrc
-
Dani about 5 yearsI'm so sorry, I wanted to upvote this, but turns out that (I don't know when) I already did. 🙏
-
flow2k about 5 yearsTLDR:
subl
is in/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl
. -
explorer about 5 yearsit is not fixing for me. I have this set up. ~ > source ~/.bash_profile ~ > echo $EDITOR subl -w ~ > subl . ~ > which subl /Users/vishlpa4/bin/subl ~ > ls -al ~/bin/subl lrwxr-xr-x 1 root staff 62 Oct 8 18:22 /Users/vishlpa4/bin/subl -> /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl...but still sublime pops up with untitled file when I do "sublime filename".
-
cardamom almost 5 yearsThanks, this worked, but just running it twice was not enough, had to remove the existing sublime with
sudo rm -rf
on the sublime directory in the applications folder first. -
chichilatte over 4 yearsWorks on High Sierra OSX 10.13.3
-
guice over 4 years^ Use this one. Soft-links into /usr/*local*/bin.
-
guice over 4 yearsSee below, use the one with /usr/*local*/bin. Try not to add custom softlinks into system directories.
-
Reihan_amn over 4 yearsit gives me this: ln: /usr/local/bin/subl: File exists What do I need to do?
-
Reihan_amn over 4 yearsI can see "sub" here: /Applications/Sublime Text.app/Contents/SharedSupport/bin I also can see both "sublime" and "subl" here: /usr/local/bin/ However, it cannot work at all! What could go wrong here?
-
Reihan_amn over 4 yearsNow working! I removed the symbolic path once using rm -f /usr/local/bin/subl and created it again by your comment. Now it is working!
-
Neeraj Jain over 4 yearsIn 2018 Only Ross's comment works, @Ross Please add your comment as answer it will definitely help others.
-
stackPusher almost 4 yearsThis works for me but it opens sublime as a "device", and my mac seems to think its different than opening sublime via the icon because i can get 2 sublimes on my dock. Why do I see sublime appear as an ejectable device when i open it with the command line after adding this to bash_profile??
-
grooveplex over 3 yearsI think this is the cleanest option of all. Thanks!
-
esaruoho about 3 yearsHow do you modify this so that it will create a file that doesn't actually exist? I know how to use open -a sublimetext to open a file that exists, but if i'm creating a new textfile, what should i modify the open script to?
-
Kent Aguilar about 3 yearsWorks for me! :)
-
Kent Aguilar about 3 years@Reihan_amn - late reply and I think you solved it already, but just as a reference. There seems to be an existing link associated to that name. You can use rm /usr/local/bin/subl then you can perform executing the symbolic link
-
PeeJee about 3 yearsAs of El Capitan's and up, you need to paste the subl file in the /usr/local/bin folder. So follow step 2 to point 6, open it in the terminal and execute the command sudo cp subl /usr/local/bin. This is because of the new System Integrity Protection feature.
-
Danodemo almost 3 yearsEveryone should be using oh-my-zsh anyways, so upvoted for visibility!
-
RustyShackleford almost 3 yearsWorks on Catalina 10.15
-
skiabox over 2 yearsAwesome!I can confirm that it still works on Catalina 10.15.4
-
arunwithasmile over 2 yearsI don't understand why we have to create symbolic links n all when this solution is SO MUCH better
-
Abhijeet Khangarot almost 2 years2021 update : I'm using Big Sur 11.1, worked perfectly
-
Jyoti Duhan over 1 yearDidn’t work for me with zsh: command not found: subl
-
Jyoti Duhan over 1 yearDidn’t work for me and failed with below lines: ln: /usr/local/bin/subl: No such file or directory Please suggest
-
Olivier JM over 1 yearWorks on Big Sur 11.4. Thanks
-
Victor Valente over 1 yearThis is the most straightforward way to do this.
-
Sam Woolf about 1 yearworks on Monterey beta
-
Vyshak about 1 yearWorked on 11.6.
-
Stickers about 1 year@JyotiDuhan zsh was added above.
-
jgarces about 1 yearAnd any way for opening several files in the same window? Because each time it opens a new one... (I've already tried this but without success). Thanks
-
meyerson about 1 yearI think this is the simplest solution
-
meyerson about 1 yearI think there are ways around this, but as given, this solution will fail when an argument feed to the subl alias is a non-existent file. I fount it more reliable to just extend PATH to include the sublime /path dir as suggested by @Artemiy
-
Mihai 11 monthsOr:
alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl $*"
-
Deepak Garg 10 monthsafter adding alias into ~/.bash_profile, do
source ~/.bash_profile
-
Ermiya Eskandary 9 months2022 update: works fantastic on macOS Monterey 12.2.1 - thank you!
-
Anver Sadhat 8 monthsexport PATH="$PATH:/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code:/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"