Install Java on Debian 11 Bullseye
Java is a high level, robust, object-oriented and secure programming language.LTS releases such as JDK 17 arrive every three years. The last LTS release, JDK 11, was published in September 2018. New releases of Java arrive every six months.Few features of Java 17 are listed below.
- Making it easier to use various PRNG algorithms interchangeably in applications.
- Improved support for stream-based programming, providing streams of PRNG objects.
- Elimination of code duplication in existing PRNG classes.
In this article, we will show you how to install java on Debian 11 system.
Step 1: install Java
First we will update apt package index.
sudo apt update
then check if Java is already installed or not using following command.
-bash: java: command not found
now we will install default open jre and jdk versions.
sudo apt install default-jre default-jdk
then check java version again
root@debian:~# java --version openjdk 11.0.12 2021-07-20 OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2) OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2, mixed mode, sharing)
If you want to install Latest Java version, then use following command.
sudo apt install openjdk-17-jre openjdk-17-jdk
openjdk 17-ea 2021-09-14 OpenJDK Runtime Environment (build 17-ea+19-Debian-1)
Also Read -> How to Install LAMP stack on Debian 11
step 2: set default java version
you can have multiple Java installations on one server. To configure which version is the default for use the following command.
sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode
Also Read -> How to Install php 8 on Debian 11 Bullseye
Step 3: set environment variable
Java applications often require JAVA environment variables to be set in the system.To run Java programs from anywhere,you need to set $JAVA_HOME.
To set the variable, edit /etc/environment file as below.
Add below line which is default install location of JAVA11.
save the file and exit and also reload the file to apply the changes to your current session.
Next, verify that the environment variable is set
That's it. Now you have successfully installed Java on Debian 11 system.
Also Read -> How to Install JAVA on Ubuntu 20 04