MacOS multi-version JDK switching

1. First install all JDk:
* JDK7, JDK8, you need to download and install the corresponding version from Oracle official website.

The default path of the JDK installed by yourself is: /Library/Java/JavaVirtualMachines/jdk1.xxjdk

2. Configure
to create a .bash_profile configuration file (skip this step if you already have this file)

1
touch  ~/.bash_profile

#vimEdit .bash_profile file

1
vim ~/.bash_profile

#If you are not used to the vim command, use the built-in text editor to open it

1
open  ~/.bash_profile

set jdk version

1
2
3
4
5
export  JAVA_7_HOME= /Library/Java/JavaVirtualMachines/jdk1 .7.0.jdk /Contents/Home
export  JAVA_8_HOME= /Library/Java/JavaVirtualMachines/jdk1 .8.0.jdk /Contents/Home
 
export  JAVA_HOME=$JAVA_7_HOME

The alias command dynamically switches the configuration of JAVA_HOME

1
2
3
alias  jdk7= 'export JAVA_HOME=$JAVA_7_HOME'
alias  jdk8=' export  JAVA_HOME=$JAVA_8_HOME’

#Save and execute the following command after the input is completed
#Re-execute the .bash_profile file

1
source  ~/.bash_profile

3. Verify:
Use: jdk7, jdk8 to switch jdk version

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326883978&siteId=291194637