Apple computer Java switching version

Effect
Insert image description here

1. Install Java1.8 and Java11

Download and install directly from the official website

2. Files after installation

/Library/Java/JavaVirtualMachines/
Insert image description here

3. Modify the configuration file

vi ~/.bash_profile

Insert image description here

#java
export JAVA_8_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home"
alias jdk8='export JAVA_HOME=$JAVA_8_HOME'

export JAVA_11_HOME="/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home"
alias jdk11='export JAVA_HOME=$JAVA_11_HOME'

# 默认使用jdk8
export JAVA_HOME=$JAVA_8_HOME
#java END

esc then:wq and press enter to save and exit.

4. Update configuration

source ~/.bash_profile

5. Version switching

Switch to Java8

jdk8

Switch to Java11

jdk11

6. Check version

java --version

Guess you like

Origin blog.csdn.net/weixin_35958891/article/details/132260492