1. First we need to know where the JDK directory is installed, follow the path below and we can find the JDK's home directory as shown in. There are two directories here because earlier versions of JDK1.8 were installed earlier in this machine.
/library/java/javavirtualmachines;
2. Because of the Mac file system structure, unlike Windows, the true home directory of the JDK is as follows:
/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home;
3. Open the terminal terminal, the default is open in their home directory, you can also directly from the CD command to jump home directory.
Open the startup file and modify the contents via vim. bash_profile command;
Enter vim and press I to enter the edit state. Add the following (modify jdk1.8.0_171 based on your own installation of the specific version). Press ESC again and enter ": Wq" to save the exit. Configure the system environment variable to end.
Export Java_home=/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home
4. Verify that the JDK1.8 is installed successfully.
In the terminal input Java, there is the following screen to prove the success of the configuration
or enter Java-version, with the following version information
Reference connection: 78046007
Mac system configuration JDK1.8 environment variables