Home > Wiki Tips

Bash Profile Mac: What Is it and How it Differ from Bashrc?

Updated on Tuesday, December 3, 2024

Written by

Sherry Song

Approved by

Jessica Shee

English Français Deutsch やまと Español Português

Summary: This post will tell you what Bash is and what bash_ profile on Mac is. 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. If you want to know more about the bash profile on Mac, just keep reading.

What is Bash and what is bash_profile on Mac?

Before learning what the bash profile on Mac is, it's necessary to know what Bash is first. Bash, short for Bourne Again SHell, is a Unix shell and command language for the GNU operating system. It allows users to interact with the operating system by typing commands directly into the Terminal. Bash is powerful because it lets users automate tasks, manipulate files, and run complex programs with simple text commands.

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 changed the default shell to Zsh and Bash still remains available as an alternative shell. You can change zsh to bash on Mac if needed.

In simple words, bash_profile is a configuration file for the Bash shell, which is a hidden file in your Mac's user directory. Essentially, the .bash_profile is your personalized settings file that helps make your Terminal experience more efficient and tailored to your needs. 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 in 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.

Bashrc vs bash_profile

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.

 Time to useSituations to use
.bash_profileDuring the creation of a login shell sessionSetting up environment variables, path modifications, and other configurations that should be set once per session.
.bashrcEvery interactive shell sessionThe functions, aliases, and commands that you want to be available in every shell session, not just the initial login.

On macOS, it's common practice to source .bashrc from within .bash_profile to ensure that both types of settings are applied in all relevant situations. This means that your customizations in .bashrc will be available whether you're in a login shell or not.

Please share this post to help more people know bashrc vs bash_profile.

 

How to create .bash_profile in Mac

If you want to create the bash profile in Mac, just follow the below steps:

  1. Open Launchpad > Other > Terminal.
  2. Type in the following command to move the home directory and press Enter: cd ~/
  3. Input the below touch command to create the bash_profile on Mac:touch .bash_profile

Or you can type nano ~/.bash_profile to create one. 

In the text editor, you can add your custom aliases, environment variables, and functions. For example, 
export PATH="$PATH:/usr/local/bin"
alias ll="ls -la"

How to edit .bash_profile on Mac

For common Mac users, it's not recommended to edit bash_profile in 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:

vi ~/.bash_profile

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 Mac in such cases. 

  1. Open a plain text editor i.e. TextEdit.
  2. Press Command + O to open the file.
  3. Move to your home directory.
  4. 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.
  5. 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:

  1. Open Finder on your Mac.
  2. Go to the user's home directory. 
  3. 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.

Hope that you can know a lot about bash_profile in Mac now, why nor share our post?