1、查看Java版本信息
admin@-Pro ~ % java -versionjava version "1.8.0_211"Java(TM) SE Runtime Environment (build 1.8.0_211-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
查看安装了那些版本(略)
admin@-Pro ~ % /usr/libexec/java_home -V
Matching Java Virtual Machines (2):1.8.211.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home1.8.0_211 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
2、查看当前的环境变量配置信息
admin@-Pro ~ % echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/mysql@5.7/bin:/Users/admin/tools/apache-maven-3.9.4/bin:/usr/local/sbin:/Users/admin/tools/gradle-8.5/bin
3、配置Java环境变量
3.1、找到Java安装路径
打开“访达” - “前往” - “前往文件夹” - 输入“Library”,找到“Java”文件夹,复制Java的home路径。 例:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home
3.2、打开.bash_profile文件
admin@-Pro ~ % vim ~/.bash_profile
3.3、添加Java配置
#java_home
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
3.4、退出保存环境变量
(1)先摁 ESC键 返回命名行模式(一定要先摁ESC)。
(2)输入 :wq 退出保存环境变量。
4、在终端输入下面命令行让环境变量生效
admin@-Pro ~ % source .bash_profile
5、再次查看环境配置信息
admin@-Pro ~ % echo $PATH
/Users/admin/tools/apache-maven3.9.4/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/mysql@5.7/bin:/Users/admin/tools/apache-maven-3.9.4/bin:/usr/local/sbin:/Users/admin/tools/gradle-8.5/bin:/usr/local/sbin:/Users/admin/tools/gradle-8.5/bin
配置结束!