Remove a Java version from system alternatives and optionally delete its files
The Delete Version command removes a Java version from the system’s alternatives database and optionally deletes the installation files from /opt/java/.
Unregister from alternatives - Removes the version from system alternatives (required)
Delete files - Removes the actual files from /opt/java/ (optional)
You can unregister a version from alternatives while keeping the files on disk. This is useful if you want to temporarily remove a version but may need to reinstall it later.
if op == "yes" { color.Info.Prompt("Enter the Java version you want to delete") color.Info.Tips("Ej. jdk-21") fmt.Scanln(&path) pathR = "/opt/java/" + path err = u.RunCommandInteractive("sudo", "rm", "-rf", pathR) if err != nil { color.Error.Println("Error: ", err) return } color.Info.Prompt("Java System Deletion")}
If you chose yes, this recursively deletes the entire Java directory.
$ javaoptionscli# Select "Delete Version" from menuDelete Java versiondrwxr-xr-x - root 12 Jan 10:30 jdk-11drwxr-xr-x - root 12 Jan 10:31 jdk-17drwxr-xr-x - root 12 Jan 10:32 jdk-21Ej. jdk-21jdk-11# Unregistering from alternatives...Do you want to delete the Java files? in /opt/javayes or notyesEnter the Java version you want to deleteEj. jdk-21jdk-11Java System Deletion# Returns to main menu after 4 seconds
$ javaoptionscli# Select "Delete Version" from menuDelete Java versiondrwxr-xr-x - root 12 Jan 10:30 jdk-11drwxr-xr-x - root 12 Jan 10:31 jdk-17Ej. jdk-21jdk-11# Unregistering from alternatives...Do you want to delete the Java files? in /opt/javayes or notnoJava is no longer in the system alternatives, but it's still in the folder /opt/java/# Returns to main menu after 4 seconds
# Check disk usage first$ du -sh /opt/java/*450M /opt/java/jdk-11480M /opt/java/jdk-17520M /opt/java/jdk-21# Delete old version$ javaoptionscli # Delete Version -> jdk-11 -> yes
Cleaning up failed installation
If a Java installation failed or is corrupted, remove it completely:
$ javaoptionscli# Delete Version -> corrupted-jdk -> yes# Then reinstall using New Version Java
Temporarily removing from alternatives
Keep files but remove from alternatives (useful for testing):
$ javaoptionscli# Delete Version -> jdk-17 -> not# Version is unregistered but files remain in /opt/java/jdk-17# Can be re-registered later if needed
Upgrading minor versions
Replace Java 17.0.8 with 17.0.9:
# Delete old version$ javaoptionscli # Delete Version -> jdk-17.0.8 -> yes# Install new version$ javaoptionscli # New Version Java -> jdk-17.0.9.tar.gz
Data cannot be recovered after deletionIf you choose to delete files, they are permanently removed with rm -rf. There is no recycle bin or undo option. Make sure you’ve selected the correct version before confirming.
Don’t delete the currently active versionBefore deleting, verify you’re not removing the currently active Java version:
$ java -version$ which java$ readlink -f $(which java)
If you delete the active version, you may break applications. Switch to a different version first using Change Version.
After deleting a version, if you have other Java versions installed, the system will automatically switch to the highest priority version in auto mode. Use List Versions to see remaining versions.