The method to set the default version of Java under Mac
- 2020-05-10 18:05:08
- OfStack
This article first shows you how to switch the Java version, and then shows you how to make it permanent.
The previous version of Mac under Java 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 version 1.8 is installed, execute
Java -version
The command still displays version 1.7 information. How do I 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
The order shall be executed after it has been executed
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 make it permanent, add the command to your profile file.
echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/' >> ~/.bash_profile
source ~/.bash_profile
conclusion
That's all you need to know to set the default version of Java under Mac. I hope the content of this article can help you in your study or work. If you have any questions, please leave a message.