This article first gave you a way to switch the Java version, and then introduced how to achieve permanent effect, the following words do not say more, together to see the detailed steps.
The previous version of Java under Mac was 1.7.
Java-version
java Version "1.7.0_71"
Java (tm) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot (tm) 64-bit Server VM (build 24.71-b01, Mixed mode)
After the 1.8 version is installed, the execution Java -version
command still displays 1.7 version information. How do I switch to version 1.8? Just execute a few of the following commands.
Export java_home=/library/java/javavirtualmachines/jdk1.8.0_40.jdk/contents/home/
export path= $JAVA _home/bin : $PATH
After the command has finished, execute the java -version
command.
Java-version
java Version "1.8.0_40"
Java (TM) SE Runtime Environment (build 1.8.0_40-b27)
Java HotSpot ( TM) 64-bit Server VM (build 25.40-b25, Mixed mode)
If you want to take effect permanently, add the command to your profile.
echo ' Export java_home=/library/java/javavirtualmachines/jdk1.8.0_40.jdk/contents/home/' >> ~/.bash_profile
Source ~/.bash_profile
Summarize
The above is the Mac set the Java default version of the full content of the method, we have learned it? Hope that the content of this article for everyone's study or work can bring some help, if you have questions you can leave a message.