1

We are building a java source. When we build it with the official repo of Ubuntu it actually installs 10.0.2. see

-------- which javac ---------------
/usr/lib/jvm/java-11-openjdk-amd64/bin/javac


-------- java -version ---------------
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)`

We need to use java 11 so we build it the way we did.

We want to find a way to reload java jdk in the following without restarting.
We would like to replace shutdown -r with some type of source or something in the following:

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-11-jdk
shutdown -r
sudo update-alternatives --config java
sudo update-alternatives --config javac

Because after a restart java -version shows openjdk version '11.0.1" 2018-10-16

What would do that?

  • Please explain and demonstrate why this is not getting updated after updating alternatives but before a reboot... (e.g. include output of java -version.) Typically alternatives system will maintain symlinks (and not $PATH settings), so the update should be available globally and immediately, since the path of the new Java is the same as the old one... But maybe the Java package is using alternatives for a file that defines environment variables... (?) Can you list what files are being managed by alternatives for "java" and "javac"? – filbranden Feb 23 at 6:52
  • @filbranden I can't really demonstrate at this point because uninstalling and re-installing "openjdk11" from cononical installs 10.0.1 and the ppa actually installs 11.0.1 and that would reak havoc. The explanation is above. – Zach Feb 23 at 19:15
1

Rebooting should not be necessary.

Your sudo update-alternatives --config java command actually does most of the job of switching the default from one version of Java to the other. However, after that command, you might need to run hash -r to get the shell of the current session to forget its old idea of where the various executables actually are and start afresh. If the java command was used while the version 10.0.1 was still the latest one installed, the shell might have cached its location and keep using it until told otherwise, with either hash -r, logout/login, or a reboot (which is overkill for this purpose).

If your friend has added something in the login scripts that explicitly sets $JAVA_HOME or any other relevant environment variables, then logging out and back in might be necessary too.

So, I'd suggest the following procedure:

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-11-jdk
sudo update-alternatives --config java
sudo update-alternatives --config javac
hash -r
java -version
<if still indicates an old version, then logout & login again>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.