A bit more detailed for beginners:
Before you begin with .bash_profile on Mac, please be aware that since macOS Catalina zsh (z shell) is the default shell. Therefore stuff we used to put in the .bash_profile now belongs to the .zshenv or the .zshrc file.
.zshenv .zshrc ? (Found here)
.zshenv: invocations of the shell. Often contains exported variables that should be available to other programs. For example, $PATH.
.zshrc: Sourced in interactive shells only. It should contain commands to set up aliases, functions, options, key bindings, etc.
STEP 1
Make sure the .bash_profile file is existing? (or the .zshenv of course) Remember that the .bash_profile file isn't there by default. You have to create it on your own.
Go into your user folder in finder.
The .bash_profile file should be findable there.
-> HD/Users/[USERNAME]
Remember: Files with a point at the beginning '.' are hidden by default.
To show hidden files in Mac OS Finder:
Press: Command + Shift + .
If it's not existing, you have to create .bash_profile on your own.
Open terminal app and switch into user folder with simple command:
cd
If it's not existing, use this command to create the file:
touch .bash_profile
STEP 2
If you can't memorise the nerdy commands for save and close in vim, nano etc (the way recommended above) the easiest way to edit is to open .bash_profile (or the .zshenv) file in your favored code editor (Sublime, Visual Studio Code, etc.).
Finder -> User folder. Right click -> open with : Visual Studio Code (or other code editor). Or drag it on app in dock.
… and there you can edit it, pass export commands in new lines.
vi ~/.bash_profile
orsubl ~/.bash_profile
ormate ~/.bash_profile
, depending on your favourite editor..bash_profile
is empty/missing then.~/.bash_profile
means it's located in the root directory.~
means root directory. 2. files prefixed with.
are invisible tols
command. They are kind of like hidden files, files the normal user doesn't really need to see. Our case here is an exception. To be able to see it you can dols -a
3.touch
will create a file at the specified directory if it doesn't exist. It it does exist then nothing will happenopen
will open it with your default texteditor. 5. As a result doingtouch ~/.bash_profile
from any directory will work. because your path is not relative~
means home (i.e.,$HOME
), not root (i.e.,/
).