Configure the environment variables in ~ / .bash_profile yourself, but the configuration will not take effect every time you restart the terminal. You need to re-execute: $ source ~ / .bash_profile
It is found that zsh loads the ~ / .zshrc file, and the task environment variable is not defined in the '.zshrc' file.
Solution
Edit the ~ / .zshrc file and add a line at the end:
source ~ / .bash_profile
Get it done ~