Last active
October 8, 2019 12:20
-
-
Save vsee/1d260fa35ffc05bc7f1ead2b391d8748 to your computer and use it in GitHub Desktop.
Java version switcher for Ubuntu
This file contains hidden or 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
#!/bin/bash | |
# Swaps between java versions | |
# | |
# Execute using the source or '.' command to set environment correctly | |
# | |
# to install alternatives after unpacking oracle java tar at /opt/jdk1.8.0_202/ execute | |
# sudo sh -c 'for bin in /opt/jdk1.8.0_202/bin/*; do update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 1500; done' | |
# | |
# to switch manually for individual bins execute | |
# sudo update-alternatives --config java | |
VERSION=$1 | |
if [ -z "$VERSION" ]; then | |
echo "ERROR: specify Java version to be 8 or 11." | |
exit 1 | |
fi | |
echo "Activating java version" $VERSION | |
if [ $VERSION -eq 11 ]; then | |
sudo sh -c 'for bin in /opt/jdk-11.0.4/bin/*; do update-alternatives --set $(basename $bin) $bin; done' | |
export JAVA_HOME="/opt/jdk-11.0.4/" | |
elif [ $VERSION -eq 8 ]; then | |
sudo sh -c 'for bin in /opt/jdk1.8.0_202/bin/*; do update-alternatives --set $(basename $bin) $bin; done' | |
export JAVA_HOME="/opt/jdk1.8.0_202/" | |
else | |
echo "ERROR: unsupported version specified:" $VERSION | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment