Mac installs multiple versions of JDK and switches versions at will + solves the error when installing eclipse on mac: Failed to create the Java Virtual Machine

1 Introduction

  • For information about installing JDK on Mac, you can read the following article, as follows:
    Installing jdk8 on Mac.

2. Download and install jdk17

  • The official website download does not require an account and password like Java8. Download 17 does not require login, download directly, official website address
    https://www.oracle.com/java/technologies/ downloads/#java17.
  • After the download is completed, you can install it directly, and then check that the jdk version has changed from 1.8 to 17, as follows:
    Insert image description here
    Insert image description here

3. Select JDK on idea

  • It doesn’t matter. It doesn’t matter if you don’t configure environment variables. The project can choose the JDK version, as follows:
    Insert image description here

4. Switch jdk version

4.1 About configuring environment variables

  • Generally, there is no need to manually configure environment variables after JDK is installed on Mac, but configuration may be required in special circumstances.

  • General situation:
    After installing the JDK, the system will adopt a jdk version by default (automatically adding the installation address to the default environment variable path), so generally we No need to manually configure environment variables. We can check the Java version currently used by the system by entering "java -version" in the terminal. If the newly installed JDK version is displayed, the installation is successful.

  • Special cases (no configuration is OK):
    We may need to manually configure environment variables, such asWhen multiple JDK versions coexist, we need to specify the version to be used in the environment variable. In this case, we need to enter some specific commands in the terminal to configure.

4.2 Switch the JDK version at will on the local Mac computer

  • My Mac version is fine without configuring it. I don’t know about others. Just select the version you need in the IDE. If you must configure it, you can follow the steps below:
    • First find the jdk installation directory
      cd /Library/Java/JavaVirtualMachines/
      
      Insert image description here
      Insert image description here
    • Configuration .zprofile file, the configuration content is as follows:
      vim .zprofile
      
      Insert image description here
      # 配置多版本jdk   begin
      export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home
      export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
      
      alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
      alias jdk17='export JAVA_HOME=$JAVA_17_HOME'
      
      export PATH=$JAVA_HOME/bin:$PATH:.
      # 配置多版本jdk   end
      
    • Remember to reload after configuring:
      source .zprofile
      
    • The effect is as follows:
      Insert image description here

5. Supplement - About installing eclipse on Mac

5.1 version introduction

  • Since the new version of eclipse requires a higher jdk version, the project requires jdk1.8, so the version I installed here isEclipse 4.16 (2020-06)(Eclipse IDE 2020-06 R)
    Insert image description here

5.2 Error——Failed to create……

  • as follows:

    Failed to create the Java Virtual Machine
    

    Insert image description here

5.3 Solving problems

  • Modify theInfo.plist file in the installation directory. The file location is as follows:
    Insert image description here
  • Modify and add the following configuration, as follows:
      <string>-vm</string>
      <string>/Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home/bin/java</string>
    
    Insert image description here
  • Just restart:
    Insert image description here

Guess you like

Origin blog.csdn.net/suixinfeixiangfei/article/details/132296094