Skip to content

Instantly share code, notes, and snippets.

@ashayh
Created September 6, 2012 21:40
Show Gist options
  • Save ashayh/3660556 to your computer and use it in GitHub Desktop.
Save ashayh/3660556 to your computer and use it in GitHub Desktop.
Install Oracle JDK 7 on Ubuntu
#!/bin/bash
JAVA_BIN="/usr/lib/jvm/jdk1.7.0/bin/java"
JAVA_CURR_BIN=$(update-alternatives --query java | awk '/^Value/{print $2}')
if [[ ${JAVA_BIN} = ${JAVA_CURR_BIN} ]] ; then
echo "Correct java already in use. Set java: ${JAVA_CURR_BIN}"
echo "About to install: ${JAVA_BIN}"
echo "Exit with nothing to do"
exit
fi
tar xzf jdk-7u7-linux-x64.tar.gz
mkdir -p /usr/lib/jvm/
rm -rf /usr/lib/jvm/jdk1.7.0
mv ./jdk1.7.0_07 /usr/lib/jvm/jdk1.7.0
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
# interactive:
#update-alternatives --config java
# non-interactive:
update-alternatives --set java ${JAVA_BIN}
JAVA_CURR_BIN=$(update-alternatives --query java | awk '/^Value/{print $2}')
echo "Installed java at ${JAVA_CURR_BIN}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment