MacOS installation and uninstallation of JDK

1. Download the JDK8 installation file

链接:https://pan.baidu.com/s/1fbYP1M38aPwKOPpw6lSVCA 
密码:u3au

Or go to the official website to download the new version, click to jump

Note: If you install other versions of Java, you only need to change the version when modifying the environment variables below.

2. Install the JDK file

2.1 Double-click the pkg file to install it

install jdk

Successfully installed the jdk file

2.2 Check the JDK installation location

Open a terminal window and execute the command:/usr/libexec/java_home -V

insert image description here

2.3 Make sure jdk is installed completely

ls -l /Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/bin/

insert image description here

3. Configure JDK environment variables

3.1 Open the terminal window and open the basic configuration file

If the environment variable is configured for the first time, use " touch .bash_profile" to create a hidden configuration file of .bash_profile.

If the configuration file .bash_profile already exists, use the " open -e .bash_profile" command directly to open the configuration file.

3.2 Configure java environment variables

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_212.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

java environment variable

3.3 Activate configuration

Enter the following command to activate the configuration:

source .bash_profile

Check the Java version:

java -version

insert image description here

3.4 Enter javac and javap to see if the installation is successful

javac
javap

4. Uninstall JDK (any version will do)

4.1 Delete the running path and running environment, etc.

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin

sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefPane

sudo rm -fr ~/Library/Application\ Support/Java

4.2 Delete the current version of jdk

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk

(Note: If you are not sure about the version number, check the current version first ls /Library/Java/JavaVirtualMachines/)

4.3 Check whether the uninstallation is successful

java -version

Guess you like

Origin blog.csdn.net/Waldocsdn/article/details/104780360