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)
- 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
2. Locate the default location of JDK installed
/usr/libexec/java_home
3. Edit the .zprofile file to add the content
export JAVA_HOME=$(/usr/libexec/java_home)
4. Source the file to apply the changes
source ~/.zprofile
5. Print the env variable to return the value
echo $JAVA_HOME
And, Voila! Its set!.
Changes will be applied to all the terminals. You can also restart your system to check if still its persisting or not (cross check).