Installation method (1) (/etc/profile)
-
First check whether JDK has been installed on your Mac system, open a terminal window and enter
java -version
. If jdk has not been installed, you will be prompted to install it. -
Then officially download the corresponding package https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html . The
Oracle
official website login account and password are saved in the memo. -
After the download is successful, click and follow the prompts to install. The default installation path is:
/Library/Java/JavaVirtualMachines
-
After installing the JDK, you need to configure environment variables, open a terminal and enter
sudo vim /etc/profile
, and enter the password as prompted. -
Press i on the keyboard to display INSERT and enteredit mode。
-
The version of Jdk has been installed by yourself:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
export JAVA_HOME
CLASS_PATH=”$JAVA_HOME/lib”
PATH=”.$PATH:$JAVA_HOME/”
-
Press
esc
to exit editing, enter:wq!
to execute and save -
Enter
source /etc/profile
, the JAVA environment variable configuration takes effect. (If promptedNo such file or directoryYou can try sudo -s and run again, please refer to https://www.cnblogs.com/ynxf/p/6290991.html) -
Enter
echo $JAVA_HOME
, if you can get the JAVA_HOME path, the JAVA environment variable is configured. -
Check the java environment: terminal input:
java -version
, the version number is displayed
Installation method (2) (~/.bash_profile)
-
Use the command
touch .bash_profile
to create a hidden configuration file named **.bash_profile**. -
If this is not the first time to configure environment variables, use the command
open .bash_profile
to open the configuration file.
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
-
Save and close the configuration file, and continue to use the command source .bash_profile to make the configuration file take effect.
-
Enter the command
java -version
to check the JDK version. If the JDK version number is output, it means that the JDK environment variable is configured successfully. For details, please refer to: https://juejin.cn/post/6844903895504797710
Uninstall method
Just enter the following four commands
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefpane
## 查找当前版本有哪些
ls /Library/Java/JavaVirtualMachines/
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk