Setting Environment Variables on macOS Catalina

In which file should I set environment variables on macOS Catalina?

I have already tried the .bash_profile file but it does't work.

3 Answers

For Zsh shell, type this in your terminal:

$ echo 'export ENV_VAR=value' >> ~/.zshenv

Then restart your terminal and type printenv to confirm if it's there.

To view the value of your env_var type the following:

$ echo $ENV_VAR

Firstly, you can set it in your ~/.bashrc

Secondly, you need to restart your shell, or run source ~/.bashrc to activate it.

Thirdly, make sure you are using bash. e.g. if using zsh then you need ~/.zshrc.

Lastly, ensure your code in the file is correct. e.g. export PATH="$PATH:/Users/tom/.cargo/bin" as a line in ~/.bashrc.

I've set in zprofile and it works. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest