How to install JDK 10 on an AWS linux instance

#!/usr/bin/env bash
cd /usr/local/src
wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" http://download.oracle.com/otn-pub/java/jdk/10.0.2+13/19aef61b38124481863b1413dce1855f/jdk-10.0.2_linux-x64_bin.tar.gz
tar xzf jdk-10.0.2_linux-x64_bin.tar.gz
rm -rf jdk-10.0.2_linux-x64_bin.tar.gz
mv /usr/local/src/jdk-10.0.2 /usr/local/jdkv10
alternatives --install /usr/bin/java java /usr/local/jdkv10/bin/java 2
alternatives --install /usr/bin/jar jar /usr/local/jdkv10/bin/jar 2
alternatives --install /usr/bin/javac javac /usr/local/jdkv10/bin/javac 2
alternatives --set jar /usr/local/jdkv10/bin/jar
alternatives --set javac /usr/local/jdkv10/bin/javac
export JAVA_HOME=/usr/local/jdkv10
export PATH=$PATH:/usr/local/jdkv10/bin
  • Save it as:
install-jdk10.sh
  • Give it execution permission with
chmod +x install-jdk10.sh
  • Run it with sudo:
sudo ./install-jdk10.sh