Friday, 18 October 2024

How to Uninstall JDK 21 on Linux OS or Amazon EC2 | Uninstalling JDK 21 on Linux and EC2 Instances

🚀 Master Cloud Computing!

Subscribe to Ram N Java for simplified AWS and Java tutorials!

SUBSCRIBE TO OUR CHANNEL

How to Uninstall JDK 21 on Linux or Amazon EC2

Removing JDK 21 from your Linux environment or an Amazon EC2 instance is a necessary step when you're upgrading or troubleshooting. This guide provides the exact terminal commands to ensure a clean and successful removal.

Step 1: Verify the Active Java Version

Before proceeding, check if JDK 21 is currently installed on your system by running:

java -version

Step 2: Locate the Installation Path

If you have multiple Java versions, use this command to find where JDK 21 is located:

sudo update-alternatives --config java

Note down the directory path (e.g., /usr/lib/jvm/java-21-amazon-corretto).

Step 3: Uninstall the JDK Package

Based on your Linux distribution, use the appropriate command to remove the package:

  • For Amazon Linux/CentOS (YUM): sudo yum remove java-21-amazon-corretto-devel
  • For Ubuntu/Debian (APT): sudo apt-get remove openjdk-21-jdk

Step 4: Clean Up Environment Variables

Don't forget to remove the JAVA_HOME path from your profile settings to avoid system errors. Open the file:

sudo nano /etc/profile

Find and delete any lines referencing JDK 21, save the file, and then refresh your environment using: source /etc/profile

Step 5: Final Verification

Run the version check one last time. If uninstalled correctly, the system will either show another version or a "command not found" error.

📥 Download the Slides & Code!

I make the PowerPoint presentation and source code available for all my viewers! You can find the direct download links in the description of the YouTube video above.

No comments:

Post a Comment

Tutorials