OS: UBUNTU 18.04
I had installed Oracle Java 8 earlier. But decided to switch to open JDK 11.
it's successfully installed.
java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)
Then I set the JAVA_HOME
sudo nano /etc/environment
File changes:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/$
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/"
Then executed:
source /etc/environment
echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64/
But the moment I exit the terminal and then launch the terminal again:
I get this output:
▶ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
which you can see is not what is expected.
Please help me out
Best Answer
To Answer the question
The answers and some comments focus on how to set
JAVA_HOME
to version 11 but the question is partly about "where is version 8 being set?". To answer that see:Use this command:
This is what my system returns. Yours will likely be different. To make a long story short the culprit is
/etc/profile.d/jdk.sh
:You probably surmise
/etc/profile.d/jdk.csh
needs changing too. Indeed it contains the exact same contents as/etc/profile.d/jdk.sh
To address the XY problem
There is a better way than going through files line by line and changing an
8
to an11
.The easiest method is using Java installer. From this Ask Ubuntu Q&A: Setting JDK 7 as default