-
-
Save agile/20c21a0ecbe7a57f6502 to your computer and use it in GitHub Desktop.
Script to switch between different Java VMs on a Debian based system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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