How to add environment variable in Mac zsh and normal terminal

Yosuva ArulanthuMacLeave a Comment

Sometimes I used to struggle to set environment variables in the Mac zsh terminal. Hope this post will be helpful for someone like me 😉

To open the environment file

nano ~/.zshenv

Sample zshenv file content

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Users/xxxx/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools

Do CTRL+X to close or save that file

To reflect the changes do the source command

source ~/.zshenv

If you are using a normal terminal do the following

Touch to create the bash_profile file

touch ~/.bash_profile

Open bash_profile

open ~/.bash_profile

Add the environment variable. save and close it

To reflect the changes do the source command

source ~/.bash_profile

Leave a Reply

Your email address will not be published.