Last active
July 22, 2024 00:25
-
-
Save tsuyo/a6fe43549599b622c8f2331a14f795da to your computer and use it in GitHub Desktop.
AWS user-data for JDK installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# You can use this script as AWS user-data like | |
# $ aws ec2 run-instances [<other_params>] --user-data https://gist.githubusercontent.com/tsuyo/a6fe43549599b622c8f2331a14f795da/raw/aws-user-data-jdk | |
JDK_URL=http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz | |
JDK_VER=jdk1.8.0_102 | |
CUR_USER=${SUDO_USER:-$(tail -1 /etc/passwd | cut -d: -f1)} | |
installJDK() { | |
yum -y install wget | |
wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" ${JDK_URL} -O /tmp/`basename ${JDK_URL}` | |
mkdir -p /usr/java | |
(cd /usr/java && tar zxvf /tmp/jdk-*.tar.gz && rm /tmp/jdk-*.tar.gz) | |
chown -R ${CUR_USER} /usr/java | |
alternatives --install /usr/bin/java java /usr/java/${JDK_VER}/bin/java 1 | |
alternatives --install /usr/bin/jar jar /usr/java/${JDK_VER}/bin/jar 1 | |
alternatives --install /usr/bin/javac javac /usr/java/${JDK_VER}/bin/javac 1 | |
alternatives --install /usr/bin/jps jps /usr/java/${JDK_VER}/bin/jps 1 | |
echo JAVA_HOME=/usr/java/${JDK_VER} >> /etc/environment | |
} | |
installJDK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment