Skip to content

Instantly share code, notes, and snippets.

@agile
Created September 18, 2014 13:33
Show Gist options
  • Save agile/20c21a0ecbe7a57f6502 to your computer and use it in GitHub Desktop.
Save agile/20c21a0ecbe7a57f6502 to your computer and use it in GitHub Desktop.
Script to switch between different Java VMs on a Debian based system
#!/usr/bin/env bash
#
# Switch between different installed Java VMs in a Debian based system
#
available=( $(update-alternatives --list java) )
if [ -n "${1}" ]; then
case "${1}" in
/*bin/java)
VM="${1}"
;;
*)
for i in "${available[@]}"; do
if [[ "${i}" =~ ${1} ]]; then
VM="${i}"
fi
done
;;
esac
if [ -n "${VM}" ]; then
echo "Switching JVM to ${VM}"
sudo update-alternatives --set java "${VM}"
else
echo "'${1}' didn't match any known jvms :("
${0}
fi
else
echo "There are ${#available[@]} installed JVM(s)..."
for vm in "${available[@]}"; do
echo " ${vm}"
done
echo
echo "USAGE: ${0} <vm name>"
fi
echo "Current JVM is $(readlink /etc/alternatives/java)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment