I want to launch sublime from a command line in Mac, using subl filename
. It seems to involve dealing with .bash_profile
. But I didn't locate the file. What steps to be taken?
4 Answers
A typical install of OS X won't create a .bash_profile
for you. When you want to run functions from your command line, this is a must-have.
- Start up Terminal
- Type
cd ~/
to go to your home folder - Type
touch .bash_profile
to create your new file. - Edit
.bash_profile
with your favorite editor (or you can just typeopen -e .bash_profile
to open it in TextEdit. - Type
. .bash_profile
to reload.bash_profile
and update any functions you add. Notice the space between the two dots!

- 175,061
- 34
- 275
- 318

- 711
- 5
- 3
-
1i'm on Mojave, this is not working. can you update you answer?. – Vatsal Shukla Jan 03 '19 at 06:05
-
1It's working on Mojave, could you explain which step isn't working with you? @Vats – Mohamed ElSawaf Mar 05 '19 at 13:29
Update I'm on Mac OS Mojave.
Open Terminal.app
and paste bellow line,
(1) touch .bash_profile
(2) open -a TextEdit.app .bash_profile
this will open a blank page in TextEdit.app
, from here you can add,update,delete
code.
I hope this will help someone.

- 1,863
- 3
- 15
- 39

- 1,274
- 12
- 25
Q1. How to check if .bash_profile
exists or not in my mac?
Solution: If you're using macOS 10.14 (Mojave) or below. Then open the Terminal.app. Run the following command to check if the .bash_profile
exists or not in your mac.
if [ -r ~/.bash_profile ];
then
echo "Yes, file exists"
else
echo "No, file does not exists"
fi
After running the above command if you get the following line - "Yes, file exists" printed in your Terminal.app. That means the file exists in your mac.
If you get the following line - "No, file does not exist" printed in your Terminal.app. That means the file does not exist in your mac.
To create a .bash_profile
file in your mac. Run the following command,
touch ~/.bash_profile
To restrict access to the .bash_profile
. Run the following command,
chmod 700 ~/.bash_profile
Q2. I want to launch sublime from a command line in Mac?
Solution: To launch sublime from mac. You can make a symlink to subl
. Assuming you've placed Sublime Text in the Applications folder, and that you have a ~/bin
directory in your path, you can run the following command:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
For more details visit the official sublime documentation

- 2,011
- 1
- 15
- 18
just create a new file - it doesn't come default with your computer. all under your user directory - ex. /Users/username
touch .bash_profile
~/.bash_profile

- 4,315
- 1
- 28
- 19