On macOS, the .bashrc
file is typically located in your home directory. Here’s a step-by-step guide to finding and editing it:
Location of .bashrc
- Path:
The file, if it exists, will be in your home directory:~/.bashrc
- Check for the file: Open a terminal and run:
ls -a ~
Look for
.bashrc
in the output. If it exists, you can edit it. - If
.bashrc
does not exist:- macOS often uses
.bash_profile
or.profile
instead of.bashrc
. You can check for these files in the same way:ls -a ~
- If you don’t find
.bashrc
, you can create one. See the How to Create a.bashrc
File section below.
- macOS often uses
What Does .bashrc
Do?
The .bashrc
file is a script that runs every time a new non-login shell session is started (e.g., opening a terminal window). It is commonly used to:
- Set environment variables.
- Create aliases.
- Define shell functions.
- Customize your shell prompt.
How to Open/Edit .bashrc
- Use a text editor like
nano
,vim
, or a GUI editor. - Example with
nano
:nano ~/.bashrc
- Make your changes and save the file. For
nano
, pressCtrl + O
to save andCtrl + X
to exit.
How to Create a .bashrc
File (if it doesn’t exist)
- Create the file:
touch ~/.bashrc
- Open it for editing:
nano ~/.bashrc
- Add your configurations (e.g., aliases, exports).
Source the File to Apply Changes
After editing .bashrc
, you need to reload it for the changes to take effect:
source ~/.bashrc
Note for macOS Users
- Default Shell on macOS: Starting with macOS Catalina (10.15), the default shell is zsh, not bash. If you’re using zsh, you’ll likely want to edit the
.zshrc
file instead:nano ~/.zshrc
- If you’re still using bash, ensure it’s your default shell by running:
echo $SHELL
If it outputs
/bin/bash
, you’re using bash.
Let me know if you have any questions or need further help!