Skip to content

Instantly share code, notes, and snippets.

@iv-m
Created October 17, 2016 06:29
Show Gist options
  • Save iv-m/04b5045be3c9ed943e3c708caf332624 to your computer and use it in GitHub Desktop.
Save iv-m/04b5045be3c9ed943e3c708caf332624 to your computer and use it in GitHub Desktop.
# Select which JDK to use
# Usage example:
# $ . use_java 1.8
JDK_DIR="$HOME/opt/jdk"
JDK_NAME=$(ls "$JDK_DIR" | grep "${1:-}" | tail -n1)
export JAVA_HOME="$JDK_DIR/$JDK_NAME"
export PATH="$JAVA_HOME/bin:$(awk -v RS=: -v ORS=: '/jdk/ {next} {print}' <<< "$PATH" | sed 's/:*$//g')"
echo "Selected JDK at $JAVA_HOME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment