How to Create and Open a .bashrc file with the macOS Terminal

Learn how to create a .bashrc shell script file via the macOS Terminal and how to open it with the nano editor.

.bashrc is a bash shell script (configuration) file used for initializing an interactive shell session. It’s specifically used for interactive non-login shells.

Now let’s learn how to create a .bashrc file and how to open and modify it via the nano editor that comes built-in with macOS.

Create .bashrc file

To create a .bashrc file, open your Mac Terminal and run this command:

touch ~/.bashrc

When you create bash files they will typically be located at the root directory of your Mac user account:


Since bash files are hidden files by default, you can use this list command to show them inside your Terminal:

ls -lha

Open .bashrc via the nano editor

To open your new .bashrc file, you can use the built-in GNU nano editor (mostly referred to as “nano”).

Run this command inside your terminal to open your .bashrc file via nano:

nano ~/.bashrc

After opening the file inside nano, you can edit it.

Warning: be careful when making changes to any bash script file, or any hidden file in general. If you follow a tutorial that requires modifying bash files, make sure you pay attention to the instructions you get, so you don’t screw anything up. If you’re in doubt, EXIT without saving your changes.

Save and quit Nano

If you have added anything to your bash files via nano, you can save and quit your data like this:

  • First hit ctrl + x
  • Then hit y (yes) to confirm you want to save the changes.
  • Then hit enter to exit the nano editor.

Quit nano without saving:

  • First hit ctrl + x
  • Then hit n (no) to confirm that you want to quit without saving changes.

Read more about the Bash shell command line.

Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊


Share & Discuss on