1, direct installation

The DMP package directly installs two versions of the JDK, such as 1.8.0_181 and 10.0.2.

2. Configure the environment

Open the environment variable configuration file bash_profile

$ vim ~/.bash_profile 

# java 
export JAVA_8_HOME="/ Library/Java/JavaVirtualMachines jdk1.8.0 _181. JDK/Contents/Home" 
export JAVA_10_HOME="/ Library/Java/JavaVirtualMachines/JDK - 10.0.2. JDK/Contents/Home" 
alias jdk8="export JAVA_HOME=$JAVA_8_HOME" 
alias jdk10="export JAVA_HOME=$JAVA_10_HOME" 
export JAVA_HOME=$JAVA_8_HOME 
export PATH="$JAVA_HOME:$PATH" 

$ source ~/.bash_profile

Copy the code

3, arbitrarily switch the Java environment

The console type jdK8 or JDk10 and it will automatically switch

JeandeMBP:~ healerjean$ jdk8 
JeandeMBP:~ healerjean$ java -version 
java version "1.8.0 comes with _181" 
Java(TM) SE Runtime Environment (build 1.8. 0 _181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode) 

JeandeMBP:~ healerjean$ jdk10 
JeandeMBP:~ healerjean$ java -version java version "10.0.2" 2018-07-17 
Java(TM) SE Runtime Environment 18.3 (build 10.02.+13) 
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.02.+13, mixed mode)

Copy the code

Delete the JDK

$ sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin

$ sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefpane
Copy the code

Find the current version

$ls/Library/Java/JavaVirtualMachines/output: jdk18.. 0 _181.jdk
Copy the code

delete

$ sudo rm -rf /Library/Java/JavaVirtualMachines/jdk18.. 0 _181.jdk
Copy the code