Instantly share code, notes, and snippets.

Embed
What would you like to do?
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

The official documentation I linked to above recommends creating a ~/bin folder (in your home directory). That's weird, I don't recall ever being asked to do that on OS X since most people install binaries within /usr/local/bin which – if you're a developer – is likely to already have tons of other binaries.

So contrary to the Sublime team recommendation, we're not going to create a bin folder in your home directory:

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

This will simply create a symlink called sublime (remember, we like names that don't suck to type 500 times a day) between the subl binary stashed in the Sublime application package, and a folder where your system usually looks for binaries to execute (launch). Think of it as a wormhole of awesome.

Now let's do a check to see if everything will run smoothly. Enter this:

open ~/.bash_profile

(In some cases the profile file is named ~/.profile)

You should see at the top of the file a line that starts with: export PATH=

This contains all the directories that will be looked into for executable binaries when you type a command in Terminal. Since we create a symlink to subl called sublime in the /usr/local/bin directory let's check if this directory is listed on that same line.

If it is, perfect. Let's keep going. If not, simply add it like this and save the file:

export PATH=/usr/local/bin:(...)

Note: The '(...)' in this example represents other folders that would be listed on the same line and separated by a colon.

If you don't already have a PATH set in your bash_profile you can type:

export PATH=/usr/local/bin:$PATH

If you had to add /usr/local/bin to your PATH, run the following command before continuing:

source ~/.bash_profile

This will reload your .bash_profile with the newly added directory.

Testing

Open a Terminal window and run:

sublime filename (replace "filename" by an actual file name)

or

sublime foldername (replace "foldername" by an actual folder name)

or even

sublime . (to open the entire current directory)

Conclusion

Now you don't need to get out of Terminal to simply open a file or a folder, you didn't have to add an "alias" or yet another bin directory to your .bash_profile which you would have needed with the official instructions given by the Sublime team.

Have fun, Sublime is a great editor showing a lot of promise.

@mapkon

This comment has been minimized.

mapkon commented Jul 6, 2012

Awesome awesome editor - not sure how i have survived without it!

@christonog

This comment has been minimized.

christonog commented Aug 10, 2012

Thanks for this, just upgraded to Mountain Lion which must've removed my sublime CLI. I go here every time I need to add sublime to the terminal and open files.

@nicolechung

This comment has been minimized.

nicolechung commented Aug 10, 2012

This worked for me, thanks!

@britishtea

This comment has been minimized.

britishtea commented Aug 18, 2012

For some reason this gives me an error:

$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
$ subl --help
-bash: /Applications/Sublime: No such file or directory

Tried escaping the spaces in Sublime Text 2 with \'s, wrapping them in quotes, still get this error. Any ideas?

@DerektheDev

This comment has been minimized.

DerektheDev commented Aug 23, 2012

Worked perfectly--great!

@krv

This comment has been minimized.

krv commented Aug 23, 2012

For those having troubles with Mountain Lion, create a bin directory first in /usr/local.

$ sudo mkdir /usr/local/bin
$ sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime
@abachuk

This comment has been minimized.

abachuk commented Aug 24, 2012

Works great for me!!! Thanks

@momer

This comment has been minimized.

momer commented Aug 28, 2012

Thank you krv

@nelsonenzo

This comment has been minimized.

nelsonenzo commented Sep 1, 2012

What I really really really like about this gist is you actually explain wtf you are doing it, and why your doing it differently than posted elsewhere ::cough::docs::cough:: Very well done, wish all instructions were this well written / described. Not only did it fix the problem, but also taught me a couple nifty tricks i hadn't thought of. Thank you!!!

@ChrisChiera

This comment has been minimized.

ChrisChiera commented Sep 4, 2012

I have a new Mac, Mountain Lion and it does not come with a Bash Profile by default. I created a blank one but am confused on what I should add exactly.

Do I add this:

export PATH=/usr/local/bin:(...)

or

export PATH=/usr/local/bin

or

export PATH=/usr/local/bin:sublime

or something else? And do I need anything else in my bash_profile for this to work? Thanks!

@johnnygoodman

This comment has been minimized.

johnnygoodman commented Sep 6, 2012

Super helpful. Thank you.

@rachelbaker

This comment has been minimized.

rachelbaker commented Sep 11, 2012

If you don't already have a PATH set in your bash_profile you can type:

export PATH=/usr/local/bin:$PATH

@edu222

This comment has been minimized.

edu222 commented Sep 16, 2012

This instructions were very helpful, I was getting frustrated with the original instructions at http://www.sublimetext.com/docs/2/osx_command_line.html

@sundeepgupta

This comment has been minimized.

sundeepgupta commented Sep 17, 2012

Thanks, I managed to get this working on my Mac, but when not while using SSH. Its giving me:
-bash: subl: command not found

@aimango

This comment has been minimized.

aimango commented Sep 21, 2012

Awesome thanks!

@clickbooq

This comment has been minimized.

clickbooq commented Sep 30, 2012

@sguptaet Make sure your bash export path has the sublime path in it. Mine looks like this:

export PATH="/usr/local/bin:/usr/local/bin/sublime:~/bin:$PATH"
@robwierzbowski

This comment has been minimized.

robwierzbowski commented Oct 23, 2012

+1. Thanks.

@DavidVII

This comment has been minimized.

DavidVII commented Oct 25, 2012

SWEEEET!

Thanks!!!

@subfuzion

This comment has been minimized.

subfuzion commented Nov 1, 2012

+1. Thanks!

@MattFielding

This comment has been minimized.

MattFielding commented Nov 14, 2012

Thanks for this, it helps me work around an issue with running a compass build with rvm from within ST2 whatwedo/sublime-text-compass#6

@ButuzGOL

This comment has been minimized.

ButuzGOL commented Dec 2, 2012

Thanks!

@nravichandra

This comment has been minimized.

nravichandra commented Dec 16, 2012

U can also add an alias to the bash_profile if u dont dont want to symlink and export path

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

and use
example:
subl filename

@LiquidNight

This comment has been minimized.

LiquidNight commented Dec 29, 2012

I have it sublime working out of the terminal, but had to use krvs helpful instructions to get it to work

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

My question out of curiosity is that after using these commands in terminal I then tried the series of tests to see if everything worked smoothly

open ~/.bash_profile .

This command does not work and terminal says that the file does not exist. I would just like to know why this is not working. I am assuming it is somehow related to the Mountain Lion configuration I set it up with?

Thanks

@cisliu

This comment has been minimized.

cisliu commented Dec 29, 2012

Awesome! I constantly got "No such file or directory" error when following the default method suggested by Sublime team and couldn't solve it in the past 20 mins. Found this, followed this, boom, everything worked like a charm! Thank you so much!

@klipnov

This comment has been minimized.

klipnov commented Jan 8, 2013

It works...Good tutorial

@hewerthomn

This comment has been minimized.

hewerthomn commented Jan 11, 2013

Thanks! This worked for me

@tonyv69

This comment has been minimized.

tonyv69 commented Jan 17, 2013

Thanks, works well for me, good work me friend!

@klebershimabuku

This comment has been minimized.

klebershimabuku commented Feb 2, 2013

Thank you for sharing this.

@humphriesjm

This comment has been minimized.

humphriesjm commented Feb 6, 2013

awesome. simple

@ghost

This comment has been minimized.

ghost commented Feb 7, 2013

awesome

@victorhazbunanuff

This comment has been minimized.

victorhazbunanuff commented Feb 10, 2013

@clickbooq Thanks.

export PATH="/usr/local/bin:/usr/local/bin/sublime:~/bin:$PATH"

@tomespen

This comment has been minimized.

tomespen commented Feb 19, 2013

Why not just add the following to your .bash_profile?
alias subl='open -a "Sublime Text 2"'

@ArtemGordinsky

This comment has been minimized.

ArtemGordinsky commented Feb 20, 2013

Thanks, Tom! Thats was much easier.

@rouzbeh84

This comment has been minimized.

rouzbeh84 commented Feb 26, 2013

Please excuse me as I am a brand new beginner when it comes to terminal. When trying to manually add "export PATH=/usr/local/bin:(...)" and then sourcing the .bash_profile file I know get "command not found" for anything i try including basic commands. I can also no longer open .bash_profile with any editor, even VIM in terminal. Please advice as no terminal commands work at all.

@addahlbe

This comment has been minimized.

addahlbe commented Feb 26, 2013

Thanks!!!

@kultom86

This comment has been minimized.

kultom86 commented Feb 26, 2013

dotRuez, "Please advice as no terminal commands work at all."

You might have solved this already but there might be others like myself who make the same mistake.

Just open the Launchpad and start Sublime Text, navigate to your home directory ( if thats not where you are currently) and you should be able to open the .bash_profile file. then just delete the content of that file. You likely do have to make sure you path to /bin as well as where you wish to create the symlink. Author might want to address this in his guide so that other OSX newbies like my self fall into this "trap".

@connorsmith

This comment has been minimized.

connorsmith commented Mar 2, 2013

Thank you!

@Rory80Hz

This comment has been minimized.

Rory80Hz commented Mar 5, 2013

Cheers, useful!

@jjamison

This comment has been minimized.

jjamison commented Mar 6, 2013

I'm getting a Permission Denied error when I run the first line at the terminal. Any advice?

@lopespm

This comment has been minimized.

lopespm commented Mar 6, 2013

Thank you very much, this was very helpful!

@jos4uke

This comment has been minimized.

jos4uke commented Mar 8, 2013

Thank you , exactly what I needed!

@chrisdigital

This comment has been minimized.

chrisdigital commented Mar 9, 2013

Thanks @artero for posting the gist and @nravichandra for your followup. It helped me get "subl" working, now I can change the command to anything I want.

@ThomasBush

This comment has been minimized.

ThomasBush commented Mar 12, 2013

So I had this working, but just upgraded to Sublime text 3, anyone know how to change the symlink? I tried navigating to usr/local/bin
rm sublime
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime

@axelsilvaferreira

This comment has been minimized.

axelsilvaferreira commented Mar 16, 2013

Very useful. thanks! :)

@devontem

This comment has been minimized.

devontem commented Mar 21, 2013

Rachel thanks so much! fixed my problem!

@silvesthu

This comment has been minimized.

silvesthu commented Mar 24, 2013

Thanks. It works well !

And I found that after using subl a terminal window will pop up, and it is some kine annoying since I'm using iTerm2 now.
I tried a more simple way.
alias sublime="open -a /Applications/Sublime\ Text\ 2.app"
It will do the same thing.

@keikoro

This comment has been minimized.

keikoro commented Mar 25, 2013

Ha @silvesthu, was looking for exactly that (also on iTerm2 currently) - thanks!

@mralexho

This comment has been minimized.

mralexho commented Mar 27, 2013

@artero Thanks for the tip. Typing sublime makes more sense to me than subl.

@wswld

This comment has been minimized.

wswld commented Mar 28, 2013

Actually, subl is just shorter. Somehow the workaround described above haven't worked for me since bash profile in Mac OS X is a mess and I'm trying to avoid that, but the simpler method, suggested by @silvesthu worked like a charm. Although I used subl as the alias. My issue was regarding launching Sublime from terminal at all.

@ghost

This comment has been minimized.

ghost commented Apr 5, 2013

@artearo please update your instructions taking into account the following:

Some users do not have a /.bash_profile. If they need to create one, they need to add the following, otherwise they will lose the default bash commands:

export PATH="/usr/local/bin:/usr/local/bin/sublime:~/bin:$PATH"

I also found that I had to manually create the sublime directory in /usr/local/bin/sublime

Finally, calling source ~/.bash_profile didn't enable the sublime command. I had to close the Terminal and restart it. If I knew that in the beginning it would have saved me 30 minutes of my time lol!

@bevacqua

This comment has been minimized.

bevacqua commented Apr 16, 2013

two thumbs up!

@evert

This comment has been minimized.

evert commented Apr 18, 2013

I also always put my own custom stuff in a local ~/bin directory. I like the idea that anything I customize to my system happens in ~bin. Furthermore, my ~bin is versioned and shared across systems.

I let OS X and Brew mess with my global stuff, but any quick binaries I may need should remain in my home directory.

@textreme

This comment has been minimized.

textreme commented Apr 25, 2013

Anyone know how to do this for Sublime Text 3?

@YZSheng

This comment has been minimized.

YZSheng commented Apr 27, 2013

Thanks a lot! Works like a charm! Though in my case, there is no ~/.bash_profile, it's ~/.profile instead. :)

@kul1

This comment has been minimized.

kul1 commented Apr 27, 2013

Thanks it worked

@daniel-zahariev

This comment has been minimized.

daniel-zahariev commented Apr 30, 2013

Thanks!

@pelumini

This comment has been minimized.

pelumini commented May 15, 2013

Thanks it worked. But I cant use same terminal to continue working except I kill the process.

@barnett

This comment has been minimized.

barnett commented May 15, 2013

Thank you!

@jcarlosmolina

This comment has been minimized.

jcarlosmolina commented May 18, 2013

Neat and to the point. Works like a breeze. Thank you!

@russoedu

This comment has been minimized.

russoedu commented May 27, 2013

@blklane, you can add a " &" after the command, so the process runs in "background" and you can continue to use your terminal.

Like this:
sudo sublime /etc/hosts &

@karna41317

This comment has been minimized.

karna41317 commented Jun 10, 2013

worked for me toooo

@mayantech

This comment has been minimized.

mayantech commented Jun 12, 2013

Tks 4 share, worked for me too

@AdamGoodApp

This comment has been minimized.

AdamGoodApp commented Jun 17, 2013

Thanks, alias sublime="open -a /Applications/Sublime\ Text\ 2.app" worked really well. Is there any difference in using this method?

@Dhavaprathap

This comment has been minimized.

Dhavaprathap commented Jun 27, 2013

Thanks it worked for me too

@RonanOD

This comment has been minimized.

RonanOD commented Jun 27, 2013

Very useful. Thanks for the tip!

@tamzheartbeatz

This comment has been minimized.

tamzheartbeatz commented Jul 1, 2013

really appreciate it, thanks krv! I was trying to figure this out and kept getting an error with other directions. this worked perfectly!

@JonathanAaron

This comment has been minimized.

JonathanAaron commented Jul 3, 2013

This is a great help.

@peterarnott

This comment has been minimized.

peterarnott commented Jul 4, 2013

My Mountain Lion Install did not include a /usr/local/bin file, instead it just had a /usr/bin. By using that instead it all worked.
Thanks for the great tutorial :D

@pkorac

This comment has been minimized.

pkorac commented Jul 9, 2013

Works like a charm, thx

@michaelar

This comment has been minimized.

michaelar commented Jul 9, 2013

Thanks for the quick guide. I didn't realize that subl was hidden inside the app bundle... Good work! :)

@sgobin

This comment has been minimized.

sgobin commented Jul 10, 2013

Thanks!

Sublime 3

For Sublime Text 3 the subl path is different so the command is:

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime
@liusashmily

This comment has been minimized.

liusashmily commented Jul 18, 2013

Hey, Neither export PATH="/usr/local/bin:/usr/local/bin/sublime:~/bin:$PATH" nor export PATH=/usr/local/bin:$PATH work for me.

So I ended up with put alias sublime="open -a /Applications/Sublime\ Text\ 2.app" into the ~/.profile, and it works great!

YEAH!

Thanks!

@lucasazevedonet

This comment has been minimized.

lucasazevedonet commented Aug 7, 2013

thx!

@samuel-henry

This comment has been minimized.

samuel-henry commented Aug 8, 2013

thanks

@comcxx11

This comment has been minimized.

comcxx11 commented Aug 11, 2013

Thanks! great example.

@thejtate

This comment has been minimized.

thejtate commented Aug 15, 2013

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

Worked like a charm in Mountain Lion. Thanks so much for the great tutorial!

@kentor

This comment has been minimized.

kentor commented Aug 28, 2013

on mac, recently, opening sublime from terminal has been acting weirdly. i'm using iTerm, and when i open a file using sublime the bar on top still says iTerm even if I have sublime focused. also, typing in sublime isn't typing in sublime, the keys show up in iTerm.

anyone else have this problem?

@Jonathan-Eyler-Werve

This comment has been minimized.

Jonathan-Eyler-Werve commented Aug 29, 2013

Well written, much thanks.

@bstrahija

This comment has been minimized.

bstrahija commented Sep 2, 2013

I personally like it better to open my files in a new windows, therefore a simple little alias ;)

alias subl="sublime -n"
@nathanbuckley

This comment has been minimized.

nathanbuckley commented Sep 3, 2013

Works perfectly. Thank you so much!!

@soltrain

This comment has been minimized.

soltrain commented Sep 5, 2013

Thank you for the fantastic explanation.

@cuixin

This comment has been minimized.

cuixin commented Sep 12, 2013

good solution, tkx so much!

@unsuthee

This comment has been minimized.

unsuthee commented Sep 21, 2013

Thanks!

@kodamirmo

This comment has been minimized.

kodamirmo commented Sep 25, 2013

Great, easy and awesome solution. Thanks!

@jeonghwan-kim

This comment has been minimized.

jeonghwan-kim commented Oct 17, 2013

Very helpful.

@Showtimes

This comment has been minimized.

Showtimes commented Nov 13, 2013

Was really confused when I kept getting:

FSPathMakeRef(/Applications/Sublime Text 2.app) failed with error -43.

While using:

alias sublime="open -a /Applications/Sublime\ Text\ 2.app"

From a recent download of sublime. I guess new downloads of sublime are not denoted as versioned? So using:

alias sublime="open -a /Applications/Sublime\ Text\.app"

worked fine.

Thanks for the awesome write up!

@mnegi

This comment has been minimized.

mnegi commented Nov 16, 2013

Really cool. Worked for me too.

@alexjamesbrown

This comment has been minimized.

alexjamesbrown commented Nov 19, 2013

Decent! :)

@jhebb

This comment has been minimized.

jhebb commented Dec 2, 2013

Instructions from krv worked for me in osx 10.9 which didn't have a /usr/local/bin folder by default.

Thanks!

@trangtungn

This comment has been minimized.

trangtungn commented Dec 4, 2013

Thanks so much for the details instruction.

@jwjb

This comment has been minimized.

jwjb commented Dec 28, 2013

@silvesthu, I am running Sublime Text 3 on OS X 10.9.1 Build 13B42 and found your instructions simple and easy and added "alias sublime="open -a /Applications/Sublime\ Text.app" to my /users/your_user_name/.bash_profile with no problem.

@maggialejandro

This comment has been minimized.

maggialejandro commented Feb 11, 2014

works great, thanks!

@rewdy

This comment has been minimized.

rewdy commented Feb 13, 2014

Thank you! This was so much more helpful than the official documentation version.

@geoffspink

This comment has been minimized.

geoffspink commented Feb 14, 2014

Great guide, but I used the alias trick as the symlink never worked.

@jessecarrigan

This comment has been minimized.

jessecarrigan commented Mar 10, 2014

Really fantastic instructions. I could never get the official version to work correctly and this only took a few minutes. Thanks for putting this together.

@csrobinson86

This comment has been minimized.

csrobinson86 commented Apr 6, 2014

Thank you...great guide appreciate 100%

@letsgoduke

This comment has been minimized.

letsgoduke commented Apr 9, 2014

Is there a way to do this using either Git Bash or Cygwin?

@jrwalker

This comment has been minimized.

jrwalker commented Apr 22, 2014

thanks! this is awesome.

@ravyg

This comment has been minimized.

ravyg commented Apr 23, 2014

Nice!

@benwtks

This comment has been minimized.

benwtks commented May 9, 2014

thanks for the help!

@antgonzales

This comment has been minimized.

antgonzales commented May 10, 2014

Worked like a charm. I was going crazy trying to get "subl" command working. Thank you!

@Frankhappens

This comment has been minimized.

Frankhappens commented May 10, 2014

Thank you. It works for me.

@JulienGenoud

This comment has been minimized.

JulienGenoud commented May 13, 2014

thanks

@tjfwalker

This comment has been minimized.

tjfwalker commented May 19, 2014

Nifty, indeed. Thanks.

@therobyouknow

This comment has been minimized.

therobyouknow commented Jun 2, 2014

Thank you very much, I found also your instructions to work perfectly.

Surprised that Sublime themselves couldn't provide this for their own tool which I supported by paying to be a registered user.

@piplayan

This comment has been minimized.

piplayan commented Jun 2, 2014

Thanks . works perfect for me

@tejbirwason

This comment has been minimized.

tejbirwason commented Jun 11, 2014

Great! Saves me a lot of misery.

@kmccoan

This comment has been minimized.

kmccoan commented Jun 14, 2014

Awesome.. thanks a bunch

@jheg

This comment has been minimized.

jheg commented Jun 18, 2014

Thanks for this!

@emma1994

This comment has been minimized.

emma1994 commented Jul 1, 2014

@clickbooq, Your comment really helped me open sublime in Iterm2.

It feels so good when this article guides you through what you are doing. Many other sources just give you a bunch of commands and those commands lead you to nowhere.

@jonairey

This comment has been minimized.

jonairey commented Jul 15, 2014

Very helpful, thank you!

@methodik

This comment has been minimized.

methodik commented Jul 18, 2014

Worked great - thanks!

@apkkadam

This comment has been minimized.

apkkadam commented Jul 25, 2014

Awesome, that worked for me. Cheers.

@paulquappe

This comment has been minimized.

paulquappe commented Aug 26, 2014

pretty nice, i also used
alias sublime="open -a /Applications/Sublime\ Text\ 2.app"
and it worked fine for me.

@mludi

This comment has been minimized.

mludi commented Sep 3, 2014

Thank you so much! Works like a charm

@fguisso

This comment has been minimized.

fguisso commented Sep 9, 2014

i did so:
create /usr/local/bin
sudo mkdir /usr/local/bin
symlink
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime
add export PATH
open ~/.bash_profile

export PATH="/usr/local/bin/sublime:$PATH"

Its worked with "sublime" command

changing for "subl"
mv /usr/local/bin/sublime /usr/local/bin/subl

export PATH="/usr/local/bin/subl:$PATH"
@samuelkobe

This comment has been minimized.

samuelkobe commented Sep 23, 2014

@fernandoGuisso thanks for the suggestion of adding the shortcut:
mv /usr/local/bin/sublime /usr/local/bin/subl

I like this way more and it was not working before with just sublime (saved my sanity).

@ysyfff

This comment has been minimized.

ysyfff commented Oct 14, 2014

awesome!!!

@funkytaco

This comment has been minimized.

funkytaco commented Nov 3, 2014

The cli app is called subl for brevity, in my opinion. Look at your command history and see how short most of the command names are in /bin. He's probably saved developers thousands of seconds. 😀

@balanza

This comment has been minimized.

balanza commented Nov 8, 2014

Just a little UPDATE for Sublime Text 3 (Mac OSX Yosemite)
The ST's folder is Sublime Text.app instead of Sublime Text 2.app, thus the command to be run slightly changes into:

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

@aasierra

This comment has been minimized.

aasierra commented Nov 21, 2014

Beautiful !

@rrrutledge

This comment has been minimized.

rrrutledge commented Nov 21, 2014

Thanks!

@GesJeremie

This comment has been minimized.

GesJeremie commented Dec 8, 2014

Awesome bro, thanks !

@trevorjh02

This comment has been minimized.

trevorjh02 commented Jan 5, 2015

I screwed up. Not sure how to fix it now. I did..

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/sub1 /usr/local/bin/sublime

sub1 instead of subl

now I have no idea how to fix it. Help would be much appreciated.

@joelfuentes

This comment has been minimized.

joelfuentes commented Jan 12, 2015

man U are awesome, the best and easier way to do it, thanks a lot.

@andreahull

This comment has been minimized.

andreahull commented Jan 26, 2015

worked perfectly. thank you!

@igor972

This comment has been minimized.

igor972 commented Jan 27, 2015

Works like a charm
<3

@chrishenzie

This comment has been minimized.

chrishenzie commented Feb 10, 2015

Thank you for these instructions.

In case anyone is struggling to run this line posted ON SUBLIME'S DOCUMENTATION (wtf guys)

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

be sure to first remove the quotations around the first arg!

@JennySwift

This comment has been minimized.

JennySwift commented Feb 13, 2015

Thanks! I was struggling for ages trying to get this to work then I followed your tutorial and finally, it worked!

@duranmla

This comment has been minimized.

duranmla commented Feb 13, 2015

Thanks!

@RohinBhargava

This comment has been minimized.

RohinBhargava commented Mar 4, 2015

Thanks so much!

@eladrianovalle

This comment has been minimized.

eladrianovalle commented Mar 7, 2015

This was a game changer for me! Awesome!

@bolatk

This comment has been minimized.

bolatk commented Mar 17, 2015

Thanks!

@reedflinch

This comment has been minimized.

reedflinch commented Apr 1, 2015

many thanks, very easy to follow

@danny-allen

This comment has been minimized.

danny-allen commented Apr 3, 2015

Awesome, cheers!

@argen

This comment has been minimized.

argen commented Apr 10, 2015

Thanks for the tutorial!

@donald-s

This comment has been minimized.

donald-s commented Apr 13, 2015

Awesome. Thanks!

@ashishtibrewal

This comment has been minimized.

ashishtibrewal commented Apr 25, 2015

Works perfectly ! :D Thank you !

@piplayan

This comment has been minimized.

piplayan commented Apr 26, 2015

works perfectly. thanks!

@sudodoki

This comment has been minimized.

sudodoki commented May 11, 2015

Thanks!
Btw, ST3 seems to have dropped the digit from the app name, so bin is in /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl

@DrShpongle

This comment has been minimized.

DrShpongle commented Jun 8, 2015

Thanks, man!

@ganesharulanantham

This comment has been minimized.

ganesharulanantham commented Jun 21, 2015

It worked for me super cool! thank you

@justMrWhite

This comment has been minimized.

justMrWhite commented Jun 27, 2015

Thanks! I'm a happier person now.

@cjliu49

This comment has been minimized.

cjliu49 commented Jun 28, 2015

I did this and now I keep getting: "-bash: open: command not found". Uhoh. Any help?

@ghost

This comment has been minimized.

ghost commented Jul 19, 2015

I just did the same for Sublime Text 3. It's nearly the same except,

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

instead for the symlink

Thanks!

@blac3kman

This comment has been minimized.

blac3kman commented Aug 4, 2015

Thanks; It works =)

@livercake

This comment has been minimized.

livercake commented Aug 7, 2015

thanks a bunch for this. each time i get a new puter, i forget to do this, then curse when it doesn't work.
you, sir, are one rad motherbleeper :)

@echoyangyang

This comment has been minimized.

echoyangyang commented Aug 15, 2015

Thank you very much!

@Deanzie

This comment has been minimized.

Deanzie commented Sep 4, 2015

great!

@RIGALSAN

This comment has been minimized.

RIGALSAN commented Sep 20, 2015

Hello,

Can someone please help me out, I cant get this to work properly. I am able to open sublime from my terminal but cant open specific files. I've tried opening up bash_profile but I've had no luck. picture attached.

Thank you,

screen shot 2015-09-20 at 1 16 47 am

@brian8128

This comment has been minimized.

brian8128 commented Oct 5, 2015

I'm using iTerm2. The command works but it also opens a regular terminal window. Is there any way to prevent this?

@nkshah

This comment has been minimized.

nkshah commented Oct 8, 2015

great! was able to use terminal to use subl path and folder / file name

@chenawu2

This comment has been minimized.

chenawu2 commented Oct 13, 2015

What do we do about El Captain? We can't edit /bin 😢

@practicous

This comment has been minimized.

practicous commented Oct 29, 2015

A life saver, thank you !!

@johndavidhunt

This comment has been minimized.

johndavidhunt commented Dec 3, 2015

Thank You, just what I was looking for!

@pedramteymoori

This comment has been minimized.

pedramteymoori commented Dec 13, 2015

Thank you man, it's great !

@sumedhav

This comment has been minimized.

sumedhav commented Dec 20, 2015

Thank you so much! This is exactly what I was looking for.

@sriharsha-sammeta

This comment has been minimized.

sriharsha-sammeta commented Dec 26, 2015

Awesome! Thanks! opening a file or directory using sublime text from terminal has now become super easy :D I will forget VI forever now

@ggrrll

This comment has been minimized.

ggrrll commented Jan 19, 2016

thanks to @tomespen

for some reason ARTERO's suggestion was not woking for me...

@tutley

This comment has been minimized.

tutley commented Jan 19, 2016

This is great!

@RanHaoCheng

This comment has been minimized.

RanHaoCheng commented Jan 25, 2016

It's worked perfectly! Thanks a lot!

@benallamar

This comment has been minimized.

benallamar commented Jan 27, 2016

Thank you so much 👍

@JoxieMedina

This comment has been minimized.

JoxieMedina commented Jan 30, 2016

Thanks, save to 🔖

@dhercher

This comment has been minimized.

dhercher commented Jan 31, 2016

Awesome!

@rogamoore

This comment has been minimized.

rogamoore commented Feb 2, 2016

For ST3 use
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Note that I removed the backslash from above and now the symlink will work.

@qetennyson

This comment has been minimized.

qetennyson commented Feb 5, 2016

Thanks for putting this together! Finally able to start working on a project in a far more convenient manner.

@shanshahed

This comment has been minimized.

shanshahed commented Feb 14, 2016

awesome.... Thanks.....

@szberko

This comment has been minimized.

szberko commented Feb 25, 2016

awesome and simple! Thank you!

@erav

This comment has been minimized.

erav commented Mar 20, 2016

the official documentation lists a very useful little option which creates a file from whatever you type into stdin:
subl -
this can be used for instance to write to a file the output of any command you type at the terminal (for instance ls):
ls | subl -

@thinkyhead

This comment has been minimized.

thinkyhead commented Mar 23, 2016

For some reason the version of subl included in the "Sublime Text 2" application bundle isn't working for me on OS X 10.11.2 El Capitan. So I ended up writing a shell script to replace it which actually works:

#!/bin/bash

for FN in "$@"; do
  if [ "$FN" = "-" ]; then
    TF=$(mktemp -t "subl stdin").txt
    cat - >"$TF"
    "$0" "$TF"
  else
    if [[ ! "$FN" =~ ^/ ]]; then
      FN="$PWD/$FN"
    fi
    FN=${FN/\"/\\\"}
    FN=${FN%/.}
    eval "osascript -e 'tell application \"Sublime Text 2\"' -e 'activate' -e 'open POSIX file \"$FN\"' -e 'end tell' -e 'return'"
  fi
done

While making an alias to open -a /path/to/Sublime Text 2 works for many cases, it doesn't work for subl -.

@neo108

This comment has been minimized.

neo108 commented Apr 7, 2016

brilliant! Thank you!

@aks0

This comment has been minimized.

aks0 commented Jun 10, 2016

thanks!

@maelsan

This comment has been minimized.

maelsan commented Jun 27, 2016

You saved my day. 👍

@ishanbakshi

This comment has been minimized.

ishanbakshi commented Jul 6, 2016

Worked like a charm ... thanks

@danyim

This comment has been minimized.

danyim commented Jul 17, 2016

For Sublime Text 3 users, this worked for me
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime

@GNJM

This comment has been minimized.

GNJM commented Jul 24, 2016

Thanks!

@ccostel

This comment has been minimized.

ccostel commented Aug 17, 2016

Thanks! Really awesome stuff.

@vikas027

This comment has been minimized.

vikas027 commented Aug 25, 2016

Thanks for sharing this. However, I like to play with aliases

~$ grep -i sublime ~/.bash_profile
alias sl='/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl'
~$
@3pns

This comment has been minimized.

3pns commented Sep 4, 2016

Awesome ! Thank you

@LehmannN

This comment has been minimized.

LehmannN commented Sep 12, 2016

Hi ! I'm getting "permission denied" from the first step. How can I get rid of this ? Thanks a lot :)

@briandjerf

This comment has been minimized.

briandjerf commented Sep 21, 2016

@NathaLalou simply enter "sudo !!" after you get "permission denied"

@ghost

This comment has been minimized.

ghost commented Sep 30, 2016

sudo !! is not a fix for the permission denied problem. does anyone have a legitimate solution for getting a permission denied message? i am an admin user.

@flummingbird

This comment has been minimized.

flummingbird commented Oct 5, 2016

Woot! thanks for this

@buluxan

This comment has been minimized.

buluxan commented Oct 6, 2016

working for me thx @vikas027

~$ grep -i sublime ~/.bash_profile
alias sl='/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl'
~$

@alyssaneub11

This comment has been minimized.

alyssaneub11 commented Oct 11, 2016

Getting the permission denied after the first step! Please help!

@mladenp

This comment has been minimized.

mladenp commented Nov 1, 2016

This is crazy complex and not working.
So i just added alias in .bash_profile like so:
alias = "open -a 'sublime text' "

@WelchCompositions

This comment has been minimized.

WelchCompositions commented Nov 30, 2016

In case anyone is having trouble this instruction is for Sublime Text 2. If your app doesnt have a number at the end of the file name change the following:

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

To:

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

in hindsight it seems obvious but caught me up for a bit!

@pooley999

This comment has been minimized.

pooley999 commented Jan 4, 2017

MacOS sierra Method:

open /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl 

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

echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile

source ~/.bash_profile

done!

@tokra

This comment has been minimized.

tokra commented Jan 12, 2017

On macOs you can simply define alias in .bash_profile e.g.: alias sublime='open -a "Sublime Text"'
everytime you open terminal, .bash_profile is sourced, and you simply can use sublime command. No need to make symlinks or export it to path. This solution is simples I ever saw. Thx

@trnt2110

This comment has been minimized.

trnt2110 commented Feb 2, 2017

Works for me, thanks!

@tallglassofmike

This comment has been minimized.

tallglassofmike commented Feb 11, 2017

@krv Exactly what I needed, 5 years later. Thanks!

@aminqp

This comment has been minimized.

aminqp commented Feb 12, 2017

Awesome ! Thank you

@whalemare

This comment has been minimized.

whalemare commented May 13, 2017

Russian translate below
Перевод на русский, кому надо, быстрее и проще
https://gist.github.com/whalemare/eb28ea4e4f45afeda33a9258c088504a

@LaurenQED

This comment has been minimized.

LaurenQED commented Jun 23, 2017

Thanks tomaspen!

Steps I took to get it to work for Sierra 10.12.5

$open ~/.bash
add to top of bash profile: alias subl='open -a "Sublime Text"'
save bash_profile
$source ~/.bash_profile
$subl .

@tonhwk

This comment has been minimized.

tonhwk commented Jul 30, 2017

I dont know how but it works! thank you!

@fr6nco

This comment has been minimized.

fr6nco commented Sep 28, 2017

Verrrry fucking useful!! thank you very much

@quantumproducer

This comment has been minimized.

quantumproducer commented Oct 14, 2017

@tomespen that won't work with doing subl ~/folder.

@lnshi

This comment has been minimized.

lnshi commented Dec 31, 2017

Really no need to be this complex, just add one line alias into your .bash_profile, then you are done:

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

subl [YOUR_FILE_PATH]

@whimsycwd

This comment has been minimized.

whimsycwd commented Jun 19, 2018

Thank you!~

@edensharvit

This comment has been minimized.

edensharvit commented Aug 12, 2018

life saver!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment