Setting up Environment Variables in macOS Big Sur, macOS Mojave, macOS Catalina, macOS Big Sur, and macOS Monterey

Please note that starting with macOS Catalina (hence including macOS Big Sur), your Mac uses zsh as the default login shell and interactive shell. bash in the default shell in macOS Mojave and earlier.

Most stories are filled with unnecessary details. I will get straight to the point so you can get what you need and move on. So here we go:

Click on your computer name. Find .bash_profile. (google how to unhide files you can’t .bash_profile in the path starting with your computer name). Right click and edit with TextEdit. Save and close.

You’re done

How to switch to a zsh profile and prompt

If you’re using a bash profile, such as to set environment variables, aliases, or path variables, you should switch to using a zsh equivalent. For example:

  • .zprofile is equivalent to .bash_profile and runs at login, including over SSH
  • .zshrc is equivalent to .bashrc and runs for each new Terminal session

If you’re using .profile (a POSIX-compliant profile), you can make zsh automatically read its settings by adding this command to .zprofile:

[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'

You can also move some settings from a bash profile to a zsh profile without modification. For example, to set environment variables: export MY_SETTING=1.

zsh recognizes a different set of prompt specifiers than bash and has a cleaner syntax for specifying colorized output, eliminating the need to use complex ANSI escape sequences. For example, here’s the syntax for a default bash prompt from .bash_profile:

export PS1="\[\e[92;40m\]\h\[\e[m\]:\[\e[93m\]\W\[\e[m\] \\$ "

To convert that bash prompt to a zsh prompt when using .zprofile or .zshrc:

export PS1="%10F%m%f:%11F%1~%f \$ "

See the zsh man page for more details.

Test your shell scripts:

To test script compatibility with Bourne-compatible shells in macOS Catalina, you can change /var/select/sh to /bin/bash, /bin/dash, or /bin/zsh. If you change /var/select/sh to a shell other than bash, be aware that scripts that make use of bashisms may not work properly.

zsh can be made to emulate sh by executing the command zsh --emulate sh.

Additional notes: zsh is highly compatible with the Bourne shell (sh) and mostly compatible with bash. More info on zsh and its command0line completion system can be obtained via man zsh in Terminal.

To change the default shell via Terminal : Enter $ chsh -s path, where path is one of the shell paths listed in /etc/shells, such as /bin/zsh, /bin/bash, /bin/csh, /bin/dash, /bin/ksh, /bin/sh, or /bin/tcsh.

To use a different shell with changing the default:

  • Open Terminal, then choose Terminal > Preferences.
  • From the General pane, select ”Command (complete path).”
  • In the field provided, enter one of the shell paths listed in /etc/shells, such as /bin/zsh, /bin/bash, /bin/csh, /bin/dash, /bin/ksh, /bin/sh, or /bin/tcsh.




In progress....

Love podcasts or audiobooks? Learn on the go with our new app.

10 Best Java Courses and Certifications for Beginners to Learn in 2022

10 Best Java Courses and Certifications for Beginners

Cloud Computing

Best Practices in Interactive Computing

Hello Command Line 👋 : An Introduction

How to Scale a Web Application

Horses racing on a track lightly covered in snow

How I hacked my workflow

Software development tools for working smarter.

Learn Spring: The Certification Class

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


In progress....

More from Medium

Fixing Italic in Visual Studio Code

GitHub Actions Basics — Hands-on Tutorial

MacOS Bootstrap 2022 — Finder

Understand IoT Connectivity in 3 min