I set JAVA_HOME in .bashrc on my Ubuntu 22.04.2 LTS system, but when I check the version, it’s still the old one:
ruomini@ruomini-XPS-13-9370:~$ echo $JAVA_HOME
/home/ruomini/jdk-17.0.7
ruomini@ruomini-XPS-13-9370:~$ java -version
openjdk version "11.0.18" 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu122.04, mixed
mode, sharing)
ruomini@ruomini-XPS-13-9370:~$
2
Answers
execute the source command /etc/profile
In Ubuntu you can run
update-alternatives --list java
then you will get a listing of properly installed JDKs/JREs the operating system knows about.
then run
update-alternatives --set <one of the list items>
to switch to a different one.