Uninstall Java on MacOS

Normally when installing Java under the platform MacOS, there is not a simple way to uninstall it, and in some cases, there are several installed versions, for that you need access to several directories to achieve it. For that reason, I have made a script in which it is checked if Java exists in MacOS, the version that owns in that machine and the most important uninstall it. The script in bash is shown below.


#!/bin/bash
# Bash Java for MacOs

PS3='Please enter your choices: '
options=("Java path" "Java Version" "Uninstall Java" "Quit")

select opt in "${options[@]}"
do
    case $opt in
        "Java path")
   _java=java
            version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
   if [ -z "$version" ] ; then
    echo no Java
   else
which java
   fi
            ;;

        "Java Version")
   _java=java
            version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
   if [ -z "$version" ] ; then
    echo no Java
   else
    echo Java version: "$version"
   fi
            ;;

        "Uninstall Java")
   _java=java
            version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
   if [ -z "$version" ] ; then
    echo no Java
   else
   sudo rm -rf /Library/Java/JavaVirtualMachines/jdk$version.jdk
     sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
   sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
   sudo rm -rf /Library/LaunchAgents/com.oracle.java.Java-Updater.plist
   sudo rm -rf /Library/PrivilegedHelperTools/com.oracle.java.JavaUpdateHelper
   sudo rm -rf /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist
   sudo rm -rf /Library/Preferences/com.oracle.java.Helper-Tool.plist
   sudo rm -rf /System/Library/Frameworks/JavaVM.framework
   sudo rm -rf /usr/bin/java
   sudo rm -rf /usr/bin/javac
   sudo rm -rf /usr/bin/javadoc
   sudo rm -rf /usr/bin/javah
   sudo rm -rf /usr/bin/javap
   sudo rm -rf /usr/bin/javaws
   sudo rm -rf /var/db/receipts/com.oracle.jdk*
   sudo rm -rf /var/db/receipts/com.oracle.jre*
   sudo rm -rf /var/root/Library/Preferences/com.oracle.javadeployment.plist
   sudo rm -rf ~/Library/Preferences/com.oracle.java.JavaAppletPlugin.plist
   sudo rm -rf ~/Library/Preferences/com.oracle.javadeployment.plist
   sudo rm -rf ~/.oracle_jre_usage
   fi
            ;;
        "Quit")
            break
            ;;
        *) echo invalid option;;
    esac
done

Comentarios