How to set .bash_profile, if it does not exist yet. I want to launch sublime from a command line in Mac
Asked Answered
S

4

39

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?

Signature answered 19/8, 2016 at 11:8 Comment(0)
T
76

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.

  1. Start up Terminal
  2. Type cd ~/ to go to your home folder
  3. Type touch .bash_profile to create your new file.
  4. Edit .bash_profile with your favorite editor (or you can just type open -e .bash_profile to open it in TextEdit.
  5. Type . .bash_profile to reload .bash_profile and update any functions you add. Notice the space between the two dots!
Touchback answered 17/1, 2017 at 23:50 Comment(2)
i'm on Mojave, this is not working. can you update you answer?.Disregard
It's working on Mojave, could you explain which step isn't working with you? @VatsRogation
D
8

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.

Disregard answered 3/1, 2019 at 6:19 Comment(0)
E
3

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

Ethnography answered 31/10, 2019 at 12:1 Comment(0)
C
2

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
Cordelier answered 3/6, 2019 at 16:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.