Tutorial to change Java version In Linux
There may have different Java versions installed on your Linux and sometime you might need to switch between different versions to work on several tasks or projects. In this tutorial, we will show you the best way to change or switch the Java version in Linux.
How To Change Java Version In Linux [2023]
Let’s check the current Java version in your Linux. Run the following command to see the current version of Java on Linux.
java -version
Run the following command to view the system’s installed Java JDKs and JREs:
sudo update-alternatives --config java
Above command displays all the available Java versions in your Linux.
Meanwhile, you can check the available Java versions using the update-alternatives command too:
sudo update-alternatives --display java
How To Install Java On Ubuntu 22.04 LTS
Run the following commands to install OpenJDK 11 package on Ubuntu 22.04 LTS.
sudo apt update sudo apt install openjdk-11-jdk
Once the installation is complete, you can verify it by checking the Java version:
java -version openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
OpenJDK 11 has been installed.
Now run the following command to install OpenJDK 8 Ubuntu 22.04 LTS.
Install Java 8 on Ubuntu On Ubuntu 22.04 LTS.
Run the below command to install OpenJDK 8 package on Ubuntu 22.04 LTS.
sudo apt update sudo apt install openjdk-8-jdk
Install Oracle Java 14 On Ubuntu 22.04 LTS.
Run the following command to download the Debian file using the command line.
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/14.0.1+7/664493ef4a6946b186ff29eb326336a2/jdk-14.0.1_linux-x64_bin.deb"
Or download the .deb package from the official download page. Once you download the Debian file, install it on your system using the command below:
sudo dpkg -i jdk-14.0.1_linux-x64_bin.deb