Install and uninstall JDK on Mac (learning record)

Installation method (1) (/etc/profile)

  1. 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.

  2. Then officially download the corresponding package https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html . The Oracleofficial website login account and password are saved in the memo.

  3. After the download is successful, click and follow the prompts to install. The default installation path is:/Library/Java/JavaVirtualMachines

  4. 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.

  5. Press i on the keyboard to display INSERT and enteredit mode

  6. 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/”
  1. Press escto exit editing, enter :wq!to execute and save

  2. 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)

  3. Enter echo $JAVA_HOME, if you can get the JAVA_HOME path, the JAVA environment variable is configured.

  4. Check the java environment: terminal input: java -version, the version number is displayed

Installation method (2) (~/.bash_profile)

  1. Use the command touch .bash_profileto create a hidden configuration file named **.bash_profile**.

  2. If this is not the first time to configure environment variables, use the command open .bash_profileto 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
  1. Save and close the configuration file, and continue to use the command source .bash_profile to make the configuration file take effect.

  2. 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

Guess you like

Origin blog.csdn.net/qq_35971258/article/details/128660895