Uninstall Java on Ubuntu

To uninstall Java on Ubuntu you can follow these steps:

  1. 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.

  2. 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
      
  3. 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

  4. Remove Java-related environment variables: Edit /etc/environmentthe 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.

  5. 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 -versionthe command again to ensure that Java has been completely uninstalled.

Guess you like

Origin blog.csdn.net/qq_46110497/article/details/131025750