Skip to content

Instantly share code, notes, and snippets.

@d0nkeyBOB
Forked from Sawaba/javainstall.sh
Last active December 15, 2019 07:29
Show Gist options
  • Save d0nkeyBOB/880a763f80d630badfb14d6cda65e61e to your computer and use it in GitHub Desktop.
Save d0nkeyBOB/880a763f80d630badfb14d6cda65e61e to your computer and use it in GitHub Desktop.
Java JDK 12 and Maven 3.6.1 install script for Windows Subsystem for Linux (WSL)
#!/bin/bash
# This script adapted from an older post on StackOverflow by user fieldju
# https://stackoverflow.com/questions/36478741/installing-oracle-jdk-on-windows-subsystem-for-linux
# The script was for JDK 8.
# Due to major changes with JDK 11 (no JRE, no Derby, Unlimited Strength included), it was necessary to update the entire script.
set -ex
# UPDATE THESE URLs (this one updated as of 2019-03-06)
export JDK_URL=https://download.oracle.com/otn-pub/java/jdk/12.0.2+10/e482c34c86bd4bf8b56c0b35558996b9/jdk-12.0.2_linux-x64_bin.tar.gz
# Download Oracle Java 11 accepting the license
wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
${JDK_URL}
# Extract the archive
tar -xzvf jdk-*.tar.gz
# clean up the tar
rm -fr jdk-*.tar.gz
# mk the jvm dir
sudo mkdir -p /usr/lib/jvm
# move the server jre
sudo mv jdk-12.* /usr/lib/jvm/oracle_jdk12
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/oracle_jdk12/bin/java 2000
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/oracle_jdk12/bin/javac 2000
wget http://apache-mirror.8birdsvideo.com/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz -P /tmp
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
sudo ln -s /opt/apache-maven-3.6.1 /opt/maven
sudo echo "export J2SDKDIR=/usr/lib/jvm/oracle_jdk12
export J2REDIR=/usr/lib/jvm/oracle_jdk12/
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=$PATH:/usr/lib/jvm/oracle_jdk12/bin:/opt/maven/bin
export JAVA_HOME=/usr/lib/jvm/oracle_jdk12" | sudo tee -a /etc/profile.d/oraclejdk.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment