Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Launch Sublime Text from the command line on OSX

Launch Sublime Text from the command line on OSX

Sublime Text includes a command line tool, subl, to work with files on the command line. This can be used to open files and projects in Sublime Text, as well working as an EDITOR for unix tools, such as git and subversion.

Requirements

  • Sublime text 2 or 3 installed in your system within Applications folder

Setup

In order to launch sublime from command line you only need to create a symlink /usr/local/bin/subl point to sublime app, to do so run the following in the command line.

Sublime Text 2

ln -sv "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Sublime Text 3

ln -sv "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Test it out

type in command line

subl test.rb

it should open new file test.rb sublime text


NOTE: To accomplish this you must:

have created a directory where you actually place binaries /usr/local/bin if not make it before creating a symlink:

mkdir -p /usr/local/bin

have /usr/local/bin in your PATH environment variable, if not add by running the following command:

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

then reload the shell:

source ~/.bash_profile

test again.

Further info read from sublime docs

@mykeverest

This comment has been minimized.

Copy link

@mykeverest mykeverest commented Dec 1, 2016

I have done all these but the code returns: -bash: subl: command not found. pls help

@jeqq

This comment has been minimized.

Copy link

@jeqq jeqq commented Jan 31, 2018

👍

@skxo

This comment has been minimized.

Copy link

@skxo skxo commented Apr 14, 2018

nice

@johnbarsoum

This comment has been minimized.

Copy link

@johnbarsoum johnbarsoum commented May 4, 2018

This was super helpful!! Thanks for this!

@calchulus

This comment has been minimized.

Copy link

@calchulus calchulus commented Jun 4, 2018

I get the following despite having gone through all of this
MacBook-Pro-6:/ calvinchu$ ln -sv "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
ln: /usr/local/bin/subl: File exists
MacBook-Pro-6:/ calvinchu$ subl test.rb
-bash: subl: command not found

@lexthor

This comment has been minimized.

Copy link

@lexthor lexthor commented Dec 27, 2018

awesome!!

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jun 8, 2019

thx

@loloangela

This comment has been minimized.

Copy link

@loloangela loloangela commented Jun 12, 2019

Thanks 👍

@terasakisatoshi

This comment has been minimized.

Copy link

@terasakisatoshi terasakisatoshi commented Jul 14, 2019

Nice

@cucoriedka

This comment has been minimized.

Copy link

@cucoriedka cucoriedka commented Jul 15, 2019

Worked first time...thank you guys :)

@hallindavid

This comment has been minimized.

Copy link

@hallindavid hallindavid commented Jul 23, 2019

I get the following despite having gone through all of this
MacBook-Pro-6:/ calvinchu$ ln -sv "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
ln: /usr/local/bin/subl: File exists
MacBook-Pro-6:/ calvinchu$ subl test.rb
-bash: subl: command not found

Hey there calchulus - I was able to get this working by removing the double quotes from around /Applications/Sublime Text......
once I did that, then did the source ~/.bash_profile it all worked

@chengbo

This comment has been minimized.

Copy link

@chengbo chengbo commented Aug 19, 2019

I get the following despite having gone through all of this
MacBook-Pro-6:/ calvinchu$ ln -sv "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
ln: /usr/local/bin/subl: File exists
MacBook-Pro-6:/ calvinchu$ subl test.rb
-bash: subl: command not found

Hey there calchulus - I was able to get this working by removing the double quotes from around /Applications/Sublime Text......
once I did that, then did the source ~/.bash_profile it all worked

Thanks @hallindavid, that works.

@iamakshayvinchurkar

This comment has been minimized.

Copy link

@iamakshayvinchurkar iamakshayvinchurkar commented Oct 14, 2019

It's Working for me thank you 😃

@VioletGiraffe

This comment has been minimized.

Copy link

@VioletGiraffe VioletGiraffe commented Oct 28, 2019

Here's the correct command:
ln -sfv /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

@aarefjev

This comment has been minimized.

Copy link

@aarefjev aarefjev commented Nov 13, 2019

On latest Catalina update had to run this:
ln -sfv /Applications/Sublime.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

@bluesplinter

This comment has been minimized.

Copy link

@bluesplinter bluesplinter commented Jan 11, 2020

Hey guys, I'm running into this problem when I try step "Sublime Text 3":

ln: /usr/local/bin/subl: Permission denied

@ddemydenko

This comment has been minimized.

Copy link

@ddemydenko ddemydenko commented Mar 3, 2020

Hey guys, I'm running into this problem when I try step "Sublime Text 3":

ln: /usr/local/bin/subl: Permission denied

the same issue

@VioletGiraffe

This comment has been minimized.

Copy link

@VioletGiraffe VioletGiraffe commented Mar 3, 2020

@ddemydenko: Did you try sudo?

@aarefjev

This comment has been minimized.

Copy link

@aarefjev aarefjev commented Mar 4, 2020

Hey guys, I'm running into this problem when I try step "Sublime Text 3":
ln: /usr/local/bin/subl: Permission denied

the same issue

quickfix would be > sudo chmod 775 /Applications/Sublime.app/Contents/SharedSupport/bin/subl

@daedae471

This comment has been minimized.

Copy link

@daedae471 daedae471 commented May 11, 2020

^ did that still didn't work :
chmod: /Applications/Sublime.app/Contents/SharedSupport/bin/subl: No such file or directory

@mauriciochirino

This comment has been minimized.

Copy link

@mauriciochirino mauriciochirino commented May 15, 2020

Awesome, thanks!

@dwijmistry11

This comment has been minimized.

Copy link

@dwijmistry11 dwijmistry11 commented Jun 18, 2020

First do "sudo su"
Then use above code
It worked for me

@MichaelHauss

This comment has been minimized.

Copy link

@MichaelHauss MichaelHauss commented Jun 29, 2020

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

Thanks, this worked

@DemonDaddy22

This comment has been minimized.

Copy link

@DemonDaddy22 DemonDaddy22 commented Sep 20, 2020

Here's the correct command:
ln -sfv /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

Thanks! This worked.
Also, this might be silly but make sure that Sublime Text is present in the Applications folder for the above commands to work. I made the same mistake and took me a few minutes to catch this.

@lolewlol

This comment has been minimized.

Copy link

@lolewlol lolewlol commented Jan 21, 2021

You can imagine the sigh of relief emitted from my kitchen table when this worked. many thanks!

@allenrocksss

This comment has been minimized.

Copy link

@allenrocksss allenrocksss commented Feb 27, 2021

I have done all these but the code returns: -bash: subl: command not found. pls help

Go to the link below and just download the Sublime Text 3. As long as you finished the installation, you can invoke subl in your terminal.

https://www.sublimetext.com/3

@Randytanpty

This comment has been minimized.

Copy link

@Randytanpty Randytanpty commented Mar 23, 2021

It works for my MacOS, thank you.

@cig0

This comment has been minimized.

Copy link

@cig0 cig0 commented Jun 25, 2021

No need to create a symbolic link when an alias can do the job in many better ways in this case:

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

This comment has been minimized.

Copy link

@Rohithv07 Rohithv07 commented Jul 7, 2021

It really helped, my problem was I didnt created the folder mentioned, when I created and continued, it worked 100%👍

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