Install Java Development Kit on Windows Subsystem for Linux
Install default JDK
Install default JDK (OpenJDK 8 at the moment of writing):
root@localhost ~ # apt install default-jdkVerify java and javac version:
user@localhost ~ $ java -versionuser@localhost ~ $ javac -versionInstall other OpenJDK versions
OpenJDK 9 (optional)
OpenJDK 9 is no longer supported and is only available from the OpenJDK archives
root@localhost ~ # /optDownload and install the OpenJDK 9 binaries
root@localhost /opt # wget -O /opt/openjdk-9.0.4_linux-x64_bin.tar.gz https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gzroot@localhost /opt #
tar xvzf openjdk-9.0.4_linux-x64_bin.tar.gzroot@localhost /opt #
ln -s jdk-9.0.4 jdk-9root@localhost /opt #
rm openjdk-9.0.4_linux-x64_bin.tar.gzOpenJDK 10 (optional)
OpenJDK 10 is available at http://jdk.java.net/10/
root@localhost ~ # /optDownload and install the OpenJDK 10 binaries
root@localhost /opt # wget https://download.java.net/java/GA/jdk10/10.0.2/19aef61b38124481863b1413dce1855f/13/openjdk-10.0.2_linux-x64_bin.tar.gzroot@localhost /opt #
tar xvzf openjdk-10.0.2_linux-x64_bin.tar.gzroot@localhost /opt #
ln -s jdk-10.0.2 jdk-10root@localhost /opt #
rm openjdk-10.0.2_linux-x64_bin.tar.gzOpenJDK 11 (optional)
OpenJDK 11 is available at http://jdk.java.net/11/
root@localhost ~ # /optDownload and install the OpenJDK 11 binaries
root@localhost /opt # wget https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gzroot@localhost /opt #
tar xvzf openjdk-11.0.1_linux-x64_bin.tar.gzroot@localhost /opt #
ln -s jdk-11.0.1 jdk-11root@localhost /opt #
rm openjdk-11.0.1_linux-x64_bin.tar.gzOpenJDK 12 (optional)
OpenJDK 12 early access is available at http://jdk.java.net/12/
root@localhost ~ # /optDownload and install the OpenJDK 12 binaries
root@localhost /opt # wget https://download.java.net/java/early_access/jdk12/16/GPL/openjdk-12-ea+16_linux-x64_bin.tar.gzroot@localhost /opt #
tar xvzf openjdk-12-ea+16_linux-x64_bin.tar.gzroot@localhost /opt #
rm openjdk-12-ea+16_linux-x64_bin.tar.gzJava switcher script (optional)
When using multiple Java versions it's useful to be able to easily switch between them. The following script updates the JAVA_HOME and the PATH for the selected JDK version.
user@localhost ~ $ nano -w ~/bin/jsw#!/usr/bin/env bash
case "${1}" in
"8")
export JAVA_HOME=""
;;
"9")
export JAVA_HOME=/opt/jdk-9
;;
"10")
export JAVA_HOME=/opt/jdk-10
;;
"11")
export JAVA_HOME=/opt/jdk-11
;;
"12")
export JAVA_HOME=/opt/jdk-12
;;
esac
export PATH="~/bin:${JAVA_HOME}/bin:/usr/local/bin:/usr/bin:/bin"
echo "${JAVA_HOME}"
echo "${PATH}"
java -version
javac -version
Verify that jsw works and sets the java and javac version.
user@localhost ~ $ source ~/bin/jsw 8user@localhost ~ $ java -versionuser@localhost ~ $ javac -versionuser@localhost ~ $ source ~/bin/jsw 9user@localhost ~ $ java -versionuser@localhost ~ $ javac -versionuser@localhost ~ $ source ~/bin/jsw 10user@localhost ~ $ java -versionuser@localhost ~ $ javac -versionuser@localhost ~ $ source ~/bin/jsw 11user@localhost ~ $ java -versionuser@localhost ~ $ javac -versionuser@localhost ~ $ source ~/bin/jsw 12user@localhost ~ $ java -versionuser@localhost ~ $ javac -versionContinue with Installing developer tools on Windows Subsystem for Linux