Mac上环境变量每次使用必须source才能生效

By gavin

先进入当前用户账户的目录下
cd ~

然后执行命令来创建 zshrc 文件
touch .zshrc
vim .zshrc

添加命令如下
source ~/.bash_profile

最后重启终端,mvn 都可以正常执行了

.bash_profile 和 .zshrc 区别:

.bash_profile 修改的环境变量只对当前窗口有效,而且需要 source 一下,.zshrc 则相当于 win 开机启动的环境变量,可以在 .zshrc 中加上一个 source 更新 .bash_profile 命令即可解决问题