'Unable to remove Java 17 from MacBook Air M1

I tried to remove Java using sudo rm -rf "/Library/Java/JavaVirtualMachines" as mentioned on Oracle docs, still Java 17 is being shown to me, after uninstalling it from my system. Any pointer to remove Java from MacBook?

arvindsangwan@Arvinds-MacBook-Air ~ % java -version
    openjdk version "17.0.1" 2021-10-19
    OpenJDK Runtime Environment (build 17.0.1+12-39)
    OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)
    arvindsangwan@Arvinds-MacBook-Air ~ % cd /Library/Java                               
    arvindsangwan@Arvinds-MacBook-Air Java % ls
    arvindsangwan@Arvinds-MacBook-Air Java %


Solution 1:[1]

Steps I performed were from here : https://www.java.com/en/download/help/mac_uninstall_java.html

  1. In the Terminal window Copy, Paste and run the commands below (one by one) :

    sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
    sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
    sudo rm -fr ~/Library/Application\ Support/Oracle/Java
    
    
  2. Then after successfully uninstalling Java, you may remove Java Deployment cache: In the Terminal window Copy and Paste the commands below:

    rm -r ~/"Library/Application Support/Oracle/Java"
    
  3. then remove the jdk folder and it's content:

    sudo rm -r -f /Library/Java/JavaVirtualMachines/jdk<"your_version">.jdk
    
  4. then perform the holy computer restart .

If you have more than 1 java version installed you may also find useful the info from this page: https://java.tutorials24x7.com/blog/how-to-switch-java-version-on-mac

Solution 2:[2]

?check your java version java -version java version "17.0.2" 2022-01-18 LTS

Change the working path to java virtual machines ? ~ cd /Library/Java/JavaVirtualMachines
check your JDK here by ls command

? JavaVirtualMachines ls

jdk-17.0.2.jdk

? JavaVirtualMachines sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk Password: ? JavaVirtualMachines ls ? JavaVirtualMachines sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane ? JavaVirtualMachines sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin ? JavaVirtualMachines sudo rm -rf ~/Library/Application\ Support/Oracle/Java

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stephen Ostermiller
Solution 2