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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like