[Java] Enable Java 8 and Java 11 SDK on Ubuntu

less than 1 minute read

Install OpenJDK 8 and 11

$ sudo apt install -y openjdk-8-jdk openjdk-11-jdk

Set environment variable JAVA_HOME

$ vi .bashrc
JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

bashrc update

$ source ~/.bashrc

Check the environment variable JAVA_HOME

$ echo $JAVA_HOME

Switch version of java command

sudo update-alternatives --config java

Switch between javac command version

sudo update-alternatives --config javac