Skip to content

Instantly share code, notes, and snippets.

@pstorch
Forked from ericeijkelenboom/emr_bootstrap_java_8.sh
Last active September 18, 2017 04:07
Show Gist options
  • Save pstorch/c217d8324c4133a003c4 to your computer and use it in GitHub Desktop.
Save pstorch/c217d8324c4133a003c4 to your computer and use it in GitHub Desktop.
Bootstrap script for installing Java 8 on an Amazon Elastic MapReduce instance (emr-4.0.0)
# Check java version
JAVA_VER=$(java -version 2>&1 | sed 's/java version "\(.*\)\.\(.*\)\..*"/\1\2/; 1q')
if [ "$JAVA_VER" -lt 18 ]
then
# Figure out how many versions of Java and javac we currently have
NR_OF_JRE_OPTIONS=$(echo 0 | alternatives --config java 2>/dev/null | grep 'There ' | awk '{print $3}' | tail -1)
NR_OF_SDK_OPTIONS=$(echo 0 | alternatives --config javac 2>/dev/null | grep 'There ' | awk '{print $3}' | tail -1)
# Silent install javac (includes jre)
sudo yum -y install java-1.8.0-devel
echo "Found $NR_OF_JRE_OPTIONS existing versions of java. Adding new version."
echo "Found $NR_OF_SDK_OPTIONS existing versions of javac. Adding new version."
# Make java 8 the default
echo $(($NR_OF_JRE_OPTIONS + 1)) | sudo alternatives --config java
echo $(($NR_OF_SDK_OPTIONS + 1)) | sudo alternatives --config javac
# Fix wrong links
sudo rm /etc/alternatives/java_sdk_openjdk;sudo ln -s /usr/lib/jvm/java-1.8.0-openjdk.x86_64 /etc/alternatives/java_sdk_openjdk
sudo rm /etc/alternatives/java_sdk_openjdk_exports;sudo ln -s /usr/lib/jvm-exports/java-1.8.0-openjdk.x86_64 /etc/alternatives/java_sdk_openjdk_exports
fi
# Check java version again
JAVA_VER=$(java -version 2>&1 | sed 's/java version "\(.*\)\.\(.*\)\..*"/\1\2/; 1q')
echo ""
echo "Java version is $JAVA_VER!"
echo "JAVA_HOME: $JAVA_HOME"
echo "JRE_HOME: $JRE_HOME"
echo "PATH: $PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment