Mac multi-version under JDK installation and management

  In Java projects often have different requirements for the JDK version, but impossible to run a project to re-download different versions of the JDK installation, so that it comes to the management of the local environment, multiple versions of the JDK.

  Mac's JDK are installed into a specified directory: / Library / Java / JavaVirtualMachines /, so you can view your installed JDK so in this directory:

      

  This shows that the present system 10, 13 installed in three versions. For installation JDK can be downloaded directly to the official website of Mac dmg need to install package. Such as screenshots:

      

  The next step is to configure the environment variables and JDK version management, first of all execute the command: vim ~ / .bash_profile modify environment variables, MAC recommended here modify environment variables, rather than modifying / etc / profile. Several configuration file differences are as follows:

        

   If you do not .bash_profile file that is created when you run the vim ~ / .bash_profile command file, and then configure the environment variables, enter the following information and save it:

export JAVA_10_HOME=/Library/java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
export JAVA_13_HOME=/Library/java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
export JAVA_7_HOME=/Library/java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
# 默认JDK为JDK10
export JAVA_HOME=$JAVA_10_HOME

# alias命令动态切换JDK版本
alias jdk7="export JAVA_HOME=$JAVA_7_HOME"
alias jdk10="export JAVA_HOME=$JAVA_10_HOME"
alias jdk13="export JAVA_HOME=$JAVA_13_HOME"

export PATH
export CLASSPATH

  Then execute the command: source ~ / .bash_profile configuration to take effect immediately, if not in effect, turn off the current Terminal and reopen.

  Execute the command: java -version view the current number version, execute the command jdk7, jdk10, jdk13 test switch is normal JDK version, as shown below:

       

Guess you like

Origin www.cnblogs.com/jing99/p/11955425.html