EDIT: I've ended up installing Microsoft's OpenJDK 21. Had a nice instructions to setup and i didnt need to mess up my debian repositories to get the thing (only add MS one). Sorry die-hard Linux fans
I'm trying to install the JRE of Java 21 in my Debian 12 headless machine, for Minecraft server purposes.
Unfortunately i saw that the packages of 21 aren't available in stable repositories, only on sid (unstable). I don't want to add the whole sid repository to avoid instability and since the only package i want is this one.
So, is there any way to install Java 21 using either apt or a .deb file - without resorting to unpack a .tar.gz? Should i download the .deb on the website and try to install it via gdebi-core? I read that this isn't an advised thing to do due to dependencies and such...
Is installing openjdk-21-jdk on Debian 12 from jdk.java.net .deb safe, if its openjdk-21 package looks not working on Debian tracker? - Unix & Linux Stack Exchange
How can i install Java 21 on Debian 12 without resorting to sid?
Why can’t I install OpenJDK 21 on debian:bookworm?
will OpenJDK 21 come to Debian 12?
Videos
Installing an archive from java.jdk.net isn’t safe, but not because of packaging issues. The Java 21 archives there don’t receive updates, and 21.0.2 is affected by a number of issues which have been fixed in later releases.
Since Debian doesn’t provide a package for Debian 12 (and probably won’t, ever — you’ll get it in 13 but I doubt it will be backported), you’ll need to download it elsewhere. A good option is to use one of the verified releases available from Adoptium.
As long as you extract the tarball in a location under /opt, /usr/local, or even your home directory, it won’t break your system. You should resist the temptation to make it available using update-alternatives, and instead rely on setting JAVA_HOME and PATH appropriately where necessary.
Stéphane Chazelas’ comments regarding the target environment are worth bearing in mind — if your goal is to produce applications for use on Debian 12, you might be better off sticking with Java 17. The upgrade to Java 21 will be much easier on Debian 13, released in August 2025. Otherwise you’ll need to manage the runtime environment wherever you need to deploy the applications you build, or use something like Quarkus and build a native application.
If the tarball contains a set of files, keep them out of the system standard directories and put them under either /opt or /usr/local. Easier to delete manually when no longer required.
If the tarball contains a deb then provided you know what you're installing, the package manager will handle dependencies and you can remove the package manually (apt remove {package}) when no longer required