Install Multiple JDK versions at the same time on Mac, and multiple jdk versions on mac

Source: Internet
Author: User

Install Multiple JDK versions at the same time on Mac, and multiple jdk versions on mac

After JDK 8 GA, We were eager to try out new features such as Java 8 Lambda. However, the main version of Java enterprise-level applications is JDK 6 and JDK 7. Therefore, I need to have JDK8, JDK7, and jdk6. JDK 6 and JDK 7 are mainly used for product code verification and their own open-source projects. JDK 8 is an early adopter. Who is the old programmer.
TargetIn the command line, you can easily switch to the corresponding Java version by running the command 'jdk6', 'jdk7', and 'jdk8'. The default value is jdk7.
Practice
1. First install all JDk:
* The built-in JDK 6 for Mac is installed in the/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/directory. * For JDK 7 and JDK 8, you need to download and install the corresponding version on the Oracle official website. The default JDK installation path is/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk.
2. Configure the JAVA_HOME path in the bash configuration file. bashrc in the user directory:

Shell code
  • Export JAVA_6_HOME =/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  • 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
  • export JAVA_6_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Homeexport JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0.jdk/Contents/Homeexport JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Homeexport JAVA_HOME=$JAVA_7_HOME

    3. Create an alias command to dynamically switch the configuration of JAVA_HOME

    Shell code
  • Alias jdk8 = 'export JAVA_HOME = $ JAVA_8_HOME'
  • Alias jdk7 = 'export JAVA_HOME = $ JAVA_7_HOME'
  • Alias jdk6 = 'export JAVA_HOME = $ JAVA_6_HOME'
  • alias jdk8='export JAVA_HOME=$JAVA_8_HOME'alias jdk7='export JAVA_HOME=$JAVA_7_HOME'alias jdk6='export JAVA_HOME=$JAVA_6_HOME'

    * Verify *

    Shell code
  • CNxnliu: Versions xnliu $ java-version
  • Java version "1.6.0 _ 65"
  • Java (TM) SE Runtime Environment (build 1.6.0 _ 65-b14-462-11M4609)
  • Java HotSpot (TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
  • CNxnliu: Versions xnliu $ jdk8
  • CNxnliu: Versions xnliu $ java-version
  • Java version "1.8.0"
  • Java (TM) SE Runtime Environment (build 1.8.0-b132)
  • Java HotSpot (TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
  • CNxnliu: Versions xnliu $
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.