This tutorial will help to install JAVA (OpenJDK) on all versions of Debian 10 Buster system. You can also use this tutorial to install Java on any Debian based systems. Let’s follow the below simple steps for the installation.
For the Oracle Java installation, users can use below link to install Oracle Java on Debian 10 system.
Step 1 – Search OpenJDK Packages
OpenJDK packages are available under native apt repositories. You can simply use
sudo apt update sudo apt search openjdk
As per above output, you can see
Step 2 – Install Java on Debian 10
Use the below command to install OpenJDK on your Debian 10 Buster systems using the package manager from the default repository. The below commands will install Java Development Kit (JDK) and Java Runtime Environment (JRE) both on your system. You can install JRE package only to setup Runtime Environment only.
sudo apt install openjdk-11-jdk
Wait for the completing installation.
Step 3 – Configure Default Java Version
The newly installed OpenJDK Java 11 will be configured as default Java version. But in some cases, you may need to change the default Java version. Run the following command on terminal:
update-alternatives –config java
This will list all configured Java versions on your system. Choose the appropriate version number as showing in below screenshot.
A star (*) shows the currently active version. Here I choose 0 for OpenJDK 11 and press enter.
After installation of Java uses below command to verify the installed version of Java on your system.
java -versionopenjdk version "11.0.6" 2020-01-14 OpenJDK Runtime Environment (build 11.0.6+10-post-Debian-1deb10u1) OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Debian-1deb10u1, mixed mode, sharing)
Step 4 – Setup Java Environment
It is the best practice to set Java environment variable after installing java. To setup java environment variabless, add the following line to /etc/profile.d/java.sh.
echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/" > /etc/profile.d/java.sh
Load the environment to current shell.
Now, the JAVA_HOME will automatically set even after system reboot. Use the following command to check the environment variable value
echo $JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/