Written byAnna Yuan
Bash Profile Mac: What Is it and How it Differs from Bashrc?
Summary: This post will tell you what is Bash and What is bash profile on Mac. It also lists how to create, edit, and delete bash profile on Mac.
When you're working with macOS, sometimes you may encounter the 'source ~/.bash_profile: command not found' error in the Terminal app. Then, you may wonder what is bash profile on Mac and how to use it. Want to know more about bash profile on Mac, just keep reading.
Table of Contents:
- 1. What is Bash
- 2. What is bash_profile on Mac
- 3. Bash_profile vs. Bashrc
- 4. How to create .bash_profile in Mac
- 5. How to edit .bash_profile on Mac
- 6. How to delete bash profile on Mac
- 7. FAQs about bash profile on Mac
What is Bash
Before learning what the bash profile on Mac is, it's necessary to know what Bash is first. Bash is a Unix shell and command language for the GNU operating system. The name is an acronym for the Bourne Again Shell, a pun on Stephen Bourne, the author of the direct ancestor of the current Unix shell.
Bash has been used as the default login shell for most Linux distributions. It is also available for the Windows platform. In addition, Bash was also the default shell in macOS Mojave and earlier. Until the release of macOS Catalina, Apple changes the default shell to Zsh and Bash still remains available as an alternative shell.
What is bash_profile on Mac
In simple words, bash_profile is a configuration file for the Bash shell, which is a hidden file in your Mac's user directory. The bash profile on Mac has loaded before Terminal loads your shell environment and contains all the startup configuration and preferences for your command-line interface. Within it, you can change your Terminal prompt, change the colors of text, add aliases to functions you use all the time, and so much more.
The bash profile on Mac is an incredibly powerful tool that can make the Terminal app infinitely easier and quicker to use. It can improve your efficiency, help you avoid time-wasting errors, and just look really pretty on your screen.
Bash_profile vs. Bashrc
When talking about the bash_profile on Mac, another Bash config file may appear in your mind - bashrc. The two files look very similar, so do you know what's the difference between bash profile and bashrc?
Bash_profile and bashrc are both files containing shell commands that are run when Bash is invoked. Bash profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
How to create .bash_profile in Mac
If you want to create the bash profile in Mac, just follow the below steps:
- Open Launchpad > Other > Terminal.
- Type in the following command to move the home directory and press Enter: cd ~/
- Input the below touch command to create the bash_profile on Mac:touch .bash_profile
How to edit .bash_profile on Mac
For common Mac users, it's not recommended to edit bash_profile on Mac by yourself since any incorrect changes may cause troubles on your Mac computer. But if you're an advanced Mac user and want to edit the bash profile on Mac, try the below methods.
To edit the .bash_profile inside the Terminal, you can use the vi command as follows:
But If the Mac bash_profile is too large, then it becomes difficult to edit in the Terminal itself. So you can use TextEdit to edit bash_profile in such cases.
- Open a plain text editor i.e. TextEdit.
- Press Command + O to open the file.
- Move to your home directory.
- There might be chances that your bash_profile is hidden in the home directory and you will not be able to see that file. Press Command + Shift + Period (.) to see the hidden file.
- Select .bash_profile, fix your problem and save it accordingly.
Alternatively, you can use the following simple command line to open and edit the bash_profile:open -a TextEdit.app ~/.bash_profile
How to delete bash profile on Mac
To delete bash_profile on Mac, it's quite simple:
- Open Finder on your Mac.
- Go to the user's home directory.
- Check if the bash_profile is visible there or not. If not, press Command + Shift + Period (.) and bash_profile will be visible. Select the bash_profile and move it to Mac Trash.
FAQs about bash profile on Mac
Zsh is more interactive and customizable than Bash. Zsh has floating-point support that Bash does not possess. Hash data structures are supported in Zsh that are not present in Bash. The invocation features in Bash is better when comparing with Zsh.
Bash is a powerful programming language, one perfectly designed for use on the command line and in shell scripts.