This is a note to self on how to install Java 21 on Ubuntu.

First let’s update!

sudo apt update -y && sudo apt upgrade -y

Install Java Development Kit 21

sudo apt install openjdk-21-jdk -y

Switch between Java versions

I have multiple versions of Java on my computer (8, 11 and 17), so to change the active version execute the following:

sudo update-alternatives --config java

Then follow the program instructions to switch to the required version of Java.