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' >> ~/.zshenvThen 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!