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-jdk
Verify java and javac version:
user@localhost
~ $
java -version
user@localhost
~ $
javac -version
Install other OpenJDK versions
OpenJDK 9 (optional)
OpenJDK 9 is no longer supported and is only available from the OpenJDK archives
root@localhost
~ #
/opt
Download 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.gz
root@localhost
/opt #
tar xvzf openjdk-9.0.4_linux-x64_bin.tar.gz
root@localhost
/opt #
ln -s jdk-9.0.4 jdk-9
root@localhost
/opt #
rm openjdk-9.0.4_linux-x64_bin.tar.gz
OpenJDK 10 (optional)
OpenJDK 10 is available at http://jdk.java.net/10/
root@localhost
~ #
/opt
Download 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.gz
root@localhost
/opt #
tar xvzf openjdk-10.0.2_linux-x64_bin.tar.gz
root@localhost
/opt #
ln -s jdk-10.0.2 jdk-10
root@localhost
/opt #
rm openjdk-10.0.2_linux-x64_bin.tar.gz
OpenJDK 11 (optional)
OpenJDK 11 is available at http://jdk.java.net/11/
root@localhost
~ #
/opt
Download 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.gz
root@localhost
/opt #
tar xvzf openjdk-11.0.1_linux-x64_bin.tar.gz
root@localhost
/opt #
ln -s jdk-11.0.1 jdk-11
root@localhost
/opt #
rm openjdk-11.0.1_linux-x64_bin.tar.gz
OpenJDK 12 (optional)
OpenJDK 12 early access is available at http://jdk.java.net/12/
root@localhost
~ #
/opt
Download 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.gz
root@localhost
/opt #
tar xvzf openjdk-12-ea+16_linux-x64_bin.tar.gz
root@localhost
/opt #
rm openjdk-12-ea+16_linux-x64_bin.tar.gz
Java 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 8
user@localhost
~ $
java -version
user@localhost
~ $
javac -version
user@localhost
~ $
source ~/bin/jsw 9
user@localhost
~ $
java -version
user@localhost
~ $
javac -version
user@localhost
~ $
source ~/bin/jsw 10
user@localhost
~ $
java -version
user@localhost
~ $
javac -version
user@localhost
~ $
source ~/bin/jsw 11
user@localhost
~ $
java -version
user@localhost
~ $
javac -version
user@localhost
~ $
source ~/bin/jsw 12
user@localhost
~ $
java -version
user@localhost
~ $
javac -version
Continue with Installing developer tools on Windows Subsystem for Linux