preface

If you enter javac hello. Java, the following information is displayed

The screen:

  • The Java file extension is.java
  • If the following information is displayed after the terminal enters the Java command, JDK has been installed

  • No error is reported when the javac hello. Java command is executed in the directory where the hello. Java file resides
  • You can see that the Java environment is not configured

Check whether the JDK is installed successfully

  • The terminal enters Java -version. If the output displays the JDK version information, the installation is successful (or use the javac/ Java command).

Java Environment Configuration

  • Enter sudo vim /etc/profile
  • Enter the MAC password and the terminal will print out the profile information. Press I to enter insert into edit mode and add the following text to the next line of FI

JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home" export JAVA_HOME CLASS_PATH="$JAVA_HOME/lib" PATH=".$PATH:$JAVA_HOME/bin"

  • Press Esc to exit editing mode and enter :wq! Press Enter to save the file.
  • Enter source /etc/profile for the Settings to take effect immediately.
  • Check whether the Java environment is configured successfully
    • Run the echo $JAVA_HOME command. If the command output is similar to the following, the Java environment is configured successfully

/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home