vim .zshrc打开zshrc文件,在配置文件里面,输入以下配置:

JAVA_HOME=/Library/JavaVirtualMachines/jdk-20.jdk/Contents/Home    --- 修改为自己的安装java应用的目录
M2_HOME=/Users/karry/Documents/development/apache-maven-3.9.1      --- 修改为自己的安装Maven应用的目录
CLASSPATH=.$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH:
export JAVA_HOME
export CLASSPATH
export PATH=$PATH:$M2_HOME/bin
export JAVA_20_HOME=`/usr/libexec/java_home -v 20`
export JAVA_HOME=$JAVA_20_HOME

具体操作如下:

karry@karrydeMac-mini ~ % vim .zshrc
JAVA_HOME=/Library/JavaVirtualMachines/jdk-20.jdk/Contents/Home
M2_HOME=/Users/karry/Documents/development/apache-maven-3.9.1
CLASSPATH=.$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH:
export JAVA_HOME
export CLASSPATH
export PATH=$PATH:$M2_HOME/bin
export JAVA_20_HOME=`/usr/libexec/java_home -v 20`
export JAVA_HOME=$JAVA_20_HOME

然后:wq保存配置
重启终端后验证环境配置安装:

karry@karrydeMac-mini ~ % java -version
java version "20" 2023-03-21
Java(TM) SE Runtime Environment (build 20+36-2344)
Java HotSpot(TM) 64-Bit Server VM (build 20+36-2344, mixed mode, sharing)
karry@karrydeMac-mini ~ % javac -version
javac 20
karry@karrydeMac-mini ~ % mvn -v
Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Maven home: /Users/karry/Documents/development/apache-maven-3.9.1
Java version: 20, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "13.2.1", arch: "aarch64", family: "mac"
karry@karrydeMac-mini ~ % 

出现以上提示及表示配置成功

标签: MacOS, MacOS配置系统环境变量, MacOS配置Java环境变量, MacOS配置Maven环境变量

添加新评论