Created
January 28, 2020 20:31
-
-
Save gorlok/69861841bee9ac64b60e7cf66e8a7497 to your computer and use it in GitHub Desktop.
Configure a new installed JDK on Ubuntu Linux
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
#!/bin/bash | |
if [ -z $1 ] | |
then | |
echo "Most provide a JDK name from /usr/lib/jvm. For instance: jdk-11" | |
exit 1 | |
fi | |
jdk=$1 | |
priority=2000 | |
jdkpath="/usr/lib/jvm/${jdk}" | |
if [ ! -d $jdkpath ] | |
then | |
echo "Does not exist a JDK at $jdkpath" | |
exit 1 | |
fi | |
echo "Installing JDK at ${jdk}" | |
CMD="java javac jar jshell" | |
for cmd in $CMD | |
do | |
file="${jdkpath}/bin/${cmd}" | |
echo "Installing command ${file}" | |
if [ -x ${file} ] | |
then | |
echo "Command ${file} found" | |
sudo update-alternatives --install /usr/bin/${cmd} $cmd $file $priority | |
sudo update-alternatives --set $cmd $file | |
echo "Command ${file} installed." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment