To uninstall Java on Ubuntu you can follow these steps:
-
Check the installed Java version: Open a terminal and run the following command to see the installed Java version on your system:
java -version
This will display installed Java version information.
-
Uninstall OpenJDK: If OpenJDK is installed on your system, you can uninstall it using the following command:
-
If you have the default OpenJDK installed:
sudo apt remove default-jdk
-
If you have a specific version of OpenJDK installed, for example 11:
sudo apt remove openjdk-11-jdk
-
-
Uninstall Oracle Java: If you have installed Oracle Java, you can uninstall it by following the steps below:
-
First, find the name of the installed Java package:
sudo update-alternatives --list java
-
Use the following command to remove each Java package:
sudo update-alternatives --remove "java" "<path_to_java_binary>"
Replace <path_to_java_binary> with the actual Java binary path, for example /usr/lib/jvm/java-11-openjdk-amd64/bin/java
-
-
Remove Java-related environment variables: Edit
/etc/environment
the file and delete the line containing the Java path. Open the file using the following command:sudo nano /etc/environment
Delete the line containing the Java path in the file and save the file.
-
Update environment variables: Run the following command to update environment variables:
source /etc/environment
After completing the above steps, Java will be successfully uninstalled. You can run java -version
the command again to ensure that Java has been completely uninstalled.