Tuesday, 22 October 2024

How to Uninstall JDK 22 on Linux OS or Amazon EC2 | Uninstall JDK 22 on Linux OS or EC2

🚀 Master Cloud & Java!

Join the Ram N Java community for simplified tech tutorials!

CLICK HERE TO SUBSCRIBE

Step-by-Step: Uninstalling JDK 22 on Linux & EC2

Managing your Linux environment efficiently often requires cleaning up older software versions. If you need to remove JDK 22 from your Linux system or an Amazon EC2 instance, this guide provides a clear, foolproof method to get it done correctly.

Step 1: Identify the Installation Path

Before deleting anything, you must know exactly where Java is located. You can find all installed Java versions and their paths by running:

sudo update-alternatives --config java

Look for the path related to JDK 22 (often found in the /opt directory or a custom folder).

Step 2: Remove the JDK 22 Directory

Once you have the path, navigate to that parent directory and use the rm command to delete the folder. For example, if it's in /opt:

sudo rm -rf /opt/jdk-22

Step 3: Clean Up Environment Variables

You likely set up JAVA_HOME in your profile files. You need to remove these lines to avoid system errors. Open your profile file (like /etc/profile or ~/.bashrc):

sudo nano /etc/profile

Find the lines referencing JDK 22, delete them, save the file, and then reload the variables:

source /etc/profile

Step 4: Update the Alternatives System

If you manually added JDK 22 to the Linux alternatives system, remove the entries for java and javac using:

sudo update-alternatives --remove "java" "/opt/jdk-22/bin/java"
sudo update-alternatives --remove "javac" "/opt/jdk-22/bin/javac"

Step 5: Verify the Uninstallation

Finally, confirm that JDK 22 is gone by checking the version:

java -version

If it was your only Java version, you will see a "command not found" error, confirming a successful removal!

📥 Get the Presentation & Code!

I provide the PowerPoint slides and source code for all my tutorials. You can find the download links directly in the description of the YouTube video above!

No comments:

Post a Comment

Tutorials