'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.
Solution 1:[1]
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
Solution 2:[2]
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
.
Solution 3:[3]
I've set in zprofile and it works. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | informatik01 |
Solution 2 | ch271828n |
Solution 3 | lallina |