OpenJDK 11 in Debian10 is installed as the default Java software package. After Debian10 is installed, you can enter Java -version in the COMMAND line interface (CLI) to view the current Java version. But some programs rely on special Java versions, such as OpenJDK 8 or Oracle JDK 11 or Oracle JDK 8. In this case, you need to install the corresponding version of the JDK in Debian 10.

This tutorial explains how to install OpenJDK 11, OpenJDK 8, Oracle JDK 11 and Oracle JDK 8 in Debian 10. With this tutorial you can learn to install the required JDK version of Java on your Debian 10 Linux server.

The premise condition

Before starting this tutorial, it is recommended that you have a VPS server or virtual machine with Debian 10 installed.

VPS server can be recommended to Ali Cloud or Vultr to buy a.

Second, you need to create a non-root user with sudo privileges on the Debian 10 system.

Install Open JDK 11

OpenJDK 11 is installed by default in Debian 10 to run Java applications developed based on OpenJDK. If you want to compile code using the javac command, you will need to complete the installation again. To complete the task, run the following command:

sudo apt-get update
sudo apt-get install default-jdk
Copy the code

After the installation is complete, run the following command to verify the installation. Open a command terminal and type:

java -version
Copy the code

Output:

openjdk version "11.0.4"2019-07-16 OpenJDK Runtime Environment (build 11.0.4+ 11-post-debian-1deb10U1) OpenJDK 64-bit Server VM (build 11.0.4+ 11-post-debian-1deb10U1 11.0.4 + 11 - post - deb10u1 Debian - 1, mixed mode, sharing)Copy the code

To check whether the JavAC is installed, run the following command:

javac -version
Copy the code

Output:

Javac 11.0.4Copy the code

At this point, OpenJDK 11 is installed.

Install Open JDK 8

Currently Java OpenJDK 8 version 8 is not available in the official Debian Buster repository, we need to use the third-party source AdoptOpenJDK to install.

First, update the package list and install the dependencies needed to add a new repository over HTTPS, using the following command:

sudo apt-get update
sudo apt install apt-transport-https ca-certificates wget dirmngr gnupg software-properties-common
Copy the code

Second, use the wget command to import the GPG key of the repository (this website may not be directly accessible in China) :

wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
Copy the code

Add the AdoptOpenJDK APT repository to your system:

sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
Copy the code

Update apt source software list, enable repository, install OpenJDK 8

sudo apt update
sudo apt install adoptopenjdk-8-hotspot
Copy the code

Run the following command on the CLI to check the installation result.

java -version
Copy the code

If other JDK versions have been installed, the system displays the same version information by default, but you need to run a command to display the Java version list and select a Java version as the default version.

sudo update-alternatives --config java
Copy the code

The output list is as follows:

[linux265@debian:~$sudo update-alternatives --config Java has two candidates to replace Java (/usr/bin/java is provided). Choose the path priority status -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * 0 / usr/lib/JVM/Java - 11 - its - amd64 / bin/Java 1111 automatic mode 1 / usr/lib/JVM/adoptopenjdk - 8 - hotspot - amd64 / bin/Java 1081 manual mode 2 /usr/lib/jvm/java-11-openJDK-amd64/bin/java 1111 Manual Mode To maintain the current value [*] press < Enter >, or type the selected number:Copy the code

OpenJDK 8 is the current default version. Enter Java -version to view the output:

Openjdk version "1.8.0_222" OpenJDK Runtime Environment (Build 1.8.0_222-b10) OpenJDK 64-bit Server VM 25.222 b10 (AdoptOpenJDK) (build, mixed mode)Copy the code

At this point, OpenJDK 8 (LTS) is installed.

Uninstall the installed Open JDK

As long as you install software through APT, you can uninstall them through apt command. So the same goes for uninstalling OpenJDK.

For example, to uninstall the default-JDK package, simply run:

sudo apt remove default-jdk
Copy the code

To uninstall the OpenJDK 8 you just installed, run the following command:

sudo apt remove adoptopenjdk-8-hotspot
Copy the code

Write in the last

Learn how to install OpenJDK 11 or OpenJDK 8 on Debian 10. Try it out on your own VPS server or virtual machine’s Debian 10 environment.