M1 multi-version JDK switching

foreword

Since the latest jdk version was 17 before September this year, I downloaded and installed it, but when I started my local tomcat, I found that jdk17 was used, but the project was jdk8, so I need to switch to jdk8, then there is That's why this article was born.

1. View the default installation path of my JDK

insert image description here

2. Modify the configuration file

vim ~/.bash_profile

I added the following configuration at the top of the file

#JAVA
export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.4.jdk/Contents/Home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home
#默认JDK1.8
export JAVA_HOME=$JAVA_8_HOME
#alias命令动态切换JDK版本
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
alias jdk17="export JAVA_HOME=$JAVA_17_HOME"

In the English input method, press the ESC key, and enter :wq!the modification of the saved file, and then use the following command to make the operation take effect

source ~/.bash_profile

3. View and switch jdk version

Use java -versionto view the current version

java version "1.8.0_333"
Java(TM) SE Runtime Environment (build 1.8.0_333-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.333-b02, mixed mode)

Switch to jdk17, console input jdk17, use java -versionto view the current version

java version "17.0.4" 2022-07-19 LTS
Java(TM) SE Runtime Environment (build 17.0.4+11-LTS-179)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.4+11-LTS-179, mixed mode, sharing)

Or switch to jdk8, use jdk8the command, and then execute it source ~/.bash_profileto switch to jdk8!
---------------------The more you know, the more you don't know----------------

Guess you like

Origin blog.csdn.net/fhf2424045058/article/details/127239853