Open sublime text from terminal in macos
In Terminal when I use
-bash: .subl: command not found
Anyone know how to open sublime text 3 from the command line in macos?
I finally managed to get it working with my osx machine I used these steps to make it work
sublfrom 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.appin the command above to
Sublime\ Text\ 3.appor
Sublime\ Text\ 2.appdepending upon where the application is stored in your
.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!
Now it's time to create your symbolic link in your
PATHfolder, BUT, before we do, let's check your profile file by using
nano ~/.bash_profile. These are the following lines that pertain to having
sublwork 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/bindirectory - I guess you could store it anywhere provided you've notified Terminal where to look for binaries.
The second line is optional and sets sublime text as the default editor The flag
-whas been added and you can find out more about flags by going to the Sublime Text docs: ST3 subl or ST2 subl
If you want to edit this file after closing it you have to run the command
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
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/sublbeing EXACTLY the same location as what you entered and verified as working in STEP 1 above. The
/usr/local/bin/sublbeing the location of where you want the symbolic link to be located - needs to be one of your
PATHlocations 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
sublfollowed by the name of the file or
.to open the current working directory.