Last Updated on January 30, 2023 by admin

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
With the above command, you can see the list of all the available JDKs and JRE. Now you need to enter the number in the confirmation prompt on the terminal to select the specific version. Once you enter the selection, you get a message which confirms that the selection is updated.
Bonus Tutorial:

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.

READ More Relevant Stuff:  How To Install Docker On Ubuntu 22.04 LTS [User Guide]

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:; oraclelicense=accept-securebackup-cookie" ""

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

Leave a comment

Your email address will not be published. Required fields are marked *