Skip to content

Instantly share code, notes, and snippets.

@patforna
Created May 21, 2014 13:43
Show Gist options
  • Save patforna/e396d982ae90659444ed to your computer and use it in GitHub Desktop.
Save patforna/e396d982ae90659444ed to your computer and use it in GitHub Desktop.
# switch between different jdk versions. usage: jdk 1.7
function jdk() {
if [ $# -ne 0 ]; then
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME="/opt/java/jdk-$@"
export PATH=$JAVA_HOME/bin:$PATH
fi
echo JAVA_HOME set to $JAVA_HOME
java -version
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment