DEV Community

lechat
lechat

Posted on

Switching Java versions by command in Ubuntu

At first install multiple versions of Java from OpenJDK.

$ sudo apt update
$ sudo apt install openjdk-8-jdk 
$ sudo apt install openjdk-11-jdk 
Enter fullscreen mode Exit fullscreen mode

Then you can switch java versions as follows:

$ update-java-alternatives --list
java-1.11.0-openjdk-amd64      1111       /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.8.0-openjdk-amd64       1081       /usr/lib/jvm/java-1.8.0-openjdk-amd64
$ sudo update-java-alternatives --set /usr/lib/jvm/java-1.11.0-openjdk-amd64
$ javac -version
javac 11.0.9.1
$ java -version
openjdk version "11.0.9.1" 2020-11-04
Enter fullscreen mode Exit fullscreen mode

If you set JAVA_HOME, maybe you have to change this too.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay