1. Download and install jdk
1.访问oracle官网, 下载jdk7:http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html#jdk-7u79-oth-JPR
2. Install jdk: Double-click the downloaded dmg file to complete the installation.
After the jdk is installed successfully, you can see the corresponding jdk version through java -version.
3. Configure the Java environment variables:
3.1 First find the real path of the currently installed jdk:
Terminal input /usr/libexec/java_home
Found that JAVA_HOME is /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
3.2 Set JAVA_HOME, PATH, CLASS_PATH:
sudo vim etc/profile
Use vi to edit the profile file
Type i to enter insert mode
At the end of the file, add the java path
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/"
CLASS_PATH="$JAVA_HOME/lib"
PATH=".;$PATH:$JAVA_HOME/bin"
After adding, press esc to exit insert mode, wq! save and exit the file.
3.3 View JAVA_HOME, PATH, CLASS_PATH: