Hi, in this case I would like to share a little bit knowledge about multiple installation of JDK based on linux os. For example, I use Linux Ubuntu OS v-18.04 LTS or you can use another linux version.
Download Oracle JDK 7 (archive), Oracle JDK 8 (archive), Oracle JDK 8 (latest), Oracle JDK 11 and Oracle JDK 17.
To see completely Oracle JDK archives, click here.
If you want to get the latest version of Oracle JDK, click here.
In your path ~/Downloads you will have 4 files of JDK.
- jdk-17_linux-x64_bin.tar.gz
- jdk-11.0.14_linux-x64_bin.tar.gz
- jdk-8u321-linux-x64.tar.gz
- jdk-7u80-linux-x64.tar.gz
Create new folder by following this command.
$ sudo mkdir -p /usr/lib/jvm
Next, you can move or copy-paste those files into /usr/lib/jvm
$ sudo cp -r jdk-17_linux-x64_bin.tar.gz /usr/lib/jvm
$ sudo cp -r jdk-11.0.14_linux-x64_bin.tar.gz /usr/lib/jvm
$ sudo cp -r jdk-8u321-linux-x64.tar.gz /usr/lib/jvm
$ sudo cp -r jdk-7u80-linux-x64.tar.gz /usr/lib/jvm
Now, move to /usr/lib/jvm by typing
$ cd /usr/lib/jvm
Extract each files.
$ sudo tar xvzf jdk-17_linux-x64_bin.tar.gz
$ sudo tar xvzf jdk-11.0.14_linux-x64_bin.tar.gz
$ sudo tar xvzf jdk-8u321-linux-x64.tar.gz
$ sudo tar xvzf jdk-7u80-linux-x64.tar.gz
You will have each folder by each JDK versions.
The question is. How to install those JDK one by one?
Follow these steps bellow for Oracle JDK 7.
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_80/bin/java" 2022007
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_80/bin/javac" 2022007
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_80/bin/javaws" 20220007
$ sudo update-alternatives --set java /usr/lib/jvm/jdk1.7.0_80/bin/java
Follow these steps bellow for Oracle JDK 8.
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_321/bin/java" 2022008
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_321/bin/javac" 2022008
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0_321/bin/javaws" 2022008
$ sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_321/bin/java
Follow these steps bellow for Oracle JDK 11.
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-11.0.14/bin/java" 2022011
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-11.0.14/bin/javac" 2022011
$ sudo update-alternatives --set java /usr/lib/jvm/jdk-11.0.14/bin/java
Follow these steps bellow for Oracle JDK 17.
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-17.0.2/bin/java" 2022017
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-17.0.2/bin/javac" 2022017
$ sudo update-alternatives --set java /usr/lib/jvm/jdk-17.0.2/bin/java
Finally, choose one version.
$ sudo update-alternatives --config java
Follow guide on your screen.
and, don`t forget to check.
$ java -version && javac -version
If your java version is not balance with javac version. For example your java version has 17.0.2 but your javac version still 11.0.14, you can check by following this command.
$ sudo update-alternatives --config javac
Choose number to javac version 17.0.2
Note:
javac version 11.0.14 must be allocated to java version 11.0.14
and also
javac version 17.0.2 must be allocated to java version 17.0.2
Done. Good luck! 😂
I hope this article can help your problem or fixed your knowledge.
See you on the next one.
Source :
https://stackoverflow.com/questions/12787757/how-to-use-the-command-update-alternatives-config-java
https://openbravotutorial.wordpress.com/2019/05/11/install-openjdk-7-on-linuxmint-19-1-or-ubuntu-18-04/
https://novicestuffs.wordpress.com/2017/04/25/how-to-uninstall-java-from-linux/
https://askubuntu.com/questions/84483/how-to-completely-uninstall-java
https://askubuntu.com/questions/60228/how-to-remove-all-files-from-a-directory
https://git-maspaad.blogspot.com/2016/11/how-to-install-java-on-ubuntu-with-apt.html
https://serverfault.com/questions/123419/linux-alternatives-config-without-user-input
Comments
Post a Comment