How to set ENV variables in MacOS BigSur

New to MacOS? And don’t know how to set the environment variables?
Here are quick steps to follow to set/edit the ENV permanently.

MacOS BigSur uses zsh (Z-shell) as its default Terminal shell.
We need to put the environment variables in ~/.zprofile or ~/.zshenv

Lets take an example, say we need to set JAVA_HOME env variable (assuming JAVA JDK setup is already done)

  1. Locate the .zprofile file in ur Home directory. If not present , create a new one and open it using following command

touch ~/.zprofile; open ~/.zprofile

/usr/libexec/java_home

export JAVA_HOME=$(/usr/libexec/java_home)

source ~/.zprofile

echo $JAVA_HOME

Changes will be applied to all the terminals. You can also restart your system to check if still its persisting or not (cross check).

--

--

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