概述
新版mac系统,打开命令行窗口。发现一些常用的命令都找不到了。
command not found: mvn
command not found: java
source /etc/profile 或者 source .bash_profile 后能生效并正常使用。但新开命令窗口后,命令又实效了,还得重新执行source
原因
较新的 MacOS 版本使用 zsh 作为终端(Terminal)和 iTerm2 的默认 shell。
可以执行命令,确认一下是否属于这种情况:
echo $SHELL
解决办法
~/.zshrc是zsh shell 启动时查找的文件,在zsh启动时先加载~/.zshrc文件。
执行以下命令,在用户目录下创建.zshrc文件:
echo "source ~/.bash_profile" >> ~/.zshrc
或者
echo "source /etc/profile" >> ~/.zshrc
取决于自己的bash配置存放在哪个文件。
相当于,让zsh先加载bash配置,再启动。搞定