I made a fresh installation of Ubuntu 24.04 LTS and installed a few apps via the App Center. One of them was IntelliJ IDEA.
With it, it brought java 23. It took me time to realize that it installed the JDK under .jdks/openjdk-23 and added it to PATH via a unknown method.
Later, I needed other JDKs to experiment with, so I installed a few openjdks - 17, 21, etc. I used sudo apt-get install openjdk-[X] for this.
IntelliJ was seeing those, however, nothing helped to change the java version in terminal.
This well accepted answer (with update-java-alternatives) didn't help, and neither did the good old setting of JAVA_HOME in a profile file.
Finally, I uninstalled IntelliJ IDEA through the App Center, and... this was also in vain! I still got java version to be 23 in terminal without having any value in JAVA_HOME. I was able to use JDK alternatives in IntelliJ itself, though, but not in terminal.
I believe this situation deserves a question here - what is the right way to install IntelliJ IDEA on Ubuntu, so that it doesn't override absolutely the JDK alternatives in terminal?
UPDATE: my solution was to remove everything from
~/.config/JetBrains, ~/cache/JetBtains and to delete the JDK from ~/.jdks/openjdk-23 .
Then, I installed multiple JDKs via apt-get and finally downloaded IDEA from the vendor site. It again installed 23 in ~/.jdks but this time it didn't override the original JDK choice.
While I fixed the situation in the ugly way, it would still be nice to know if this is a bug, and if there is a smoother way to resolve it.