This article first introduces to you how to switch the Java version, and then introduces how to achieve permanent effect. I won’t say much about it below, let’s take a look at the detailed steps together.
Previously, the Java version under Mac was 1.7.
java -versionjava 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 installing version 1.8, the Java -version command still displays the 1.7 version information. How to switch to version 1.8? Just execute 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 is executed, execute the java -version command.
java -versionjava 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 file.
echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/' >> ~/.bash_profilesource ~/.bash_profile
Summarize
The above is all about setting the default version of Java on Mac. Have you learned it? I hope the content of this article will be of some help to everyone's study or work. If you have any questions, you can leave a message.