Can't reset my JAVA_HOME to new Open JDK 11 Java installation

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:

  • `grep`ing all files for a string takes a long time

Use this command:

$ sudo grep -rnw --exclude-dir={boot,dev,lib,media,mnt,proc,root,run,sys,/tmp,tmpfs,var} '/' -e '/usr/lib/jvm/java-8-oracle' | grep JAVA_HOME

/etc/profile.d/jdk.sh:4:export JAVA_HOME=/usr/lib/jvm/java-8-oracle
/etc/profile.d/jdk.csh:4:setenv JAVA_HOME /usr/lib/jvm/java-8-oracle
/home/rick/.gradle/daemon/4.6/daemon-14831.out.log:53:20:45:23.553 [DEBUG] (... SNIP ...) /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin (... SNIP ...) Configuring env variables: {PATH=/home/rick/bin:/home/rick/.local/bin:/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin,  (... SNIP ...) 

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:

$ cat /etc/profile.d/jdk.sh

setenv J2SDKDIR /usr/lib/jvm/java-8-oracle
setenv J2REDIR /usr/lib/jvm/java-8-oracle/jre
setenv PATH ${PATH}:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
setenv JAVA_HOME /usr/lib/jvm/java-8-oracle
setenv DERBY_HOME /usr/lib/jvm/java-8-oracle/db

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 an 11.

The easiest method is using Java installer. From this Ask Ubuntu Q&A: Setting JDK 7 as default

To get a list of your installed Java platforms, run the following command from the terminal:

sudo update-alternatives --config java

This will give you a list output similar to this:

There are 2 choices for the alternative java (providing /usr/bin/java).
   Selection    Path                                           Priority   Status
  ------------------------------------------------------------
  0            /usr/lib/jvm/java-6-oracle/jre/bin/java         1070      auto mode
  1            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1051      manual mode
* 2            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1069      manual mode
Press enter to keep the current choice[*], or type selection number: 

The simplest place to set this is in .bashrc which can be done quickly this way:

echo JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/ >> .bashrc

This will make it the last line read as bash initializes and should ensure that JAVA_HOME is correctly set. If you need to do something more complicated you'll want to read up a bit on how terminal initializes. I'd recommend you start by google-ing bashrc.