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...
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!