将变量设置在~/.zshrc 后重启即可,
经过尝试,写在~/.bash_profile 或 /etc/profile 文件里时只有使用 source 时才能临时生效, 而写在~/.zshrc 文件里时开机即可生效,希望对大家的工作或学习有所帮助。
我电脑上设置的环境变量如下:
menglong@menglong ~ % cat ~/.zshrc
export mvn=/Users/menglong/kafka/apache-maven-3.6.3
export kafka=/opt/kafka_2.12-2.5.0
export zk=/opt/apache-zookeeper-3.6.1-bin
export PATH=$PATH:/opt/jmeter/apache-jmeter-5.3/bin:/usr/local/mysql/support-files:/usr/local/mysql-5.6.41-macos10.13-x86_64/bin:$mvn/bin:$kafka/bin:$zk/bin/:/usr/local/opt/inetutils/libexec/gnubin
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8