The Java JDK (Java Development Kit) is a software development environment used for developing Java Applications. The JDK is a collection of programming tools, notably JRE (Java Runtime Environment), Java (Loader for Java Application), Javac (Compiler), Jar (Archiver), etc.
On the other hand, we have JRE (Java Runtime Environment), including all components required to run programs written in the Java programming language.
OpenJDK or Oracle Java
OpenJDK is an open-source implementation of Oracle’s proprietary Java Development Kit (JDK). Oracle develops Oracle Java SE, whereas the OpenJDK is now developed by Oracle Corporation, OpenJDK and Java Community, Red Hat, IBM, Azul Systems, Apple Inc, and SAP SE.
There is no technical difference between OpenJDK and Oracle JDK.
Install Java on Debian 11
Install OpenJDK or Oracle Java as per your requirement.
You can have multiple versions of Java (OpenJDK and Oracle Java) on your system. But, you can have only one default version.
Install OpenJDK
Installing OpenJDK in Debian is a pretty straightforward process. You can use the apt command to install OpenJDK.
OpenJDK v8 is not available in Debian 11. However, you can install Oracle Java 8.Install OpenJDK JDK
### Default Java JDK ### sudo apt install -y default-jdk ### Java JDK 11 ### sudo apt install -y openjdk-11-jdkInstall OpenJDK JRE
### Default JRE ### sudo apt install -y default-jre ### Java JRE 11 ### sudo apt install -y openjdk-11-jre
Install Oracle Java
There is no separate JRE (Java Runtime Environment) anymore in Oracle Java. Instead, Oracle JDK now provides JRE as well.
Download Oracle Java
You can either use the command line or browser to download Oracle Java.
Go to the Oracle JDK page to download packages using the browser. Then, download the Debian binary package for easy installation.
Oracle Java JDK 12:
Download Oracle Java 16 (v16.0.2)
Oracle Java JDK 11 (LTS):
Download Oracle Java 11 LTS (v11.0.12) (Login Required)
Oracle Java JDK 8:
Download Oracle Java 8 (v8u301) (Login Required)
If you still want to use the command line, use the below command.
### Oracle Java JDK 16 ### wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/16.0.2%2B7/d4a915d82b4c4fbb9bde534da945d746/jdk-16.0.2_linux-x64_bin.deb ### Oracle Java JDK 11 ### wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/11.0.12%2B8/f411702ca7704a54a79ead0c2e0942a3/jdk-11.0.12_linux-x64_bin.deb ### Oracle Java JDK 8 ### wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u301-b09/d3c52aa6bfa54d3ca74e617f18309292/jdk-8u301-linux-x64.tar.gz
Install / Extract the downloaded Oracle Java package.
### Oracle JAVA JDK 16 ### sudo apt install -y ./jdk-16.0.2_linux-x64_bin.deb ### Oracle JAVA JDK 11 ### sudo apt install -y ./jdk-11.0.12_linux-x64_bin.deb ### Oracle JAVA JDK 8 ### sudo mkdir -p /usr/lib/jvm/ sudo tar -zxvf jdk-8u301-linux-x64.tar.gz -C /usr/lib/jvm/Install Oracle Java JDK/JRE
Run update-alternatives commands to install Java on your system.
### Oracle Java 16 ### sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-16.*/bin/java 1 ### Oracle Java 11 ### sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.*/bin/java 2 ### Oracle Java 8 ### sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.*/bin/java 3
Set Default Java Version
Use the alternatives command to set the default java version.
sudo update-alternatives --config java
Select Java:
If your system has multiple Java versions, then the command would list all Java versions like below.
There are 4 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/jdk-11.0.12/bin/java 2 manual mode 3 /usr/lib/jvm/jdk-16.0.2/bin/java 1 manual mode * 4 /usr/lib/jvm/jdk1.8.0_301/bin/java 3 manual mode Press to keep the current choice[*], or type selection number: 1
Enter the number below the selection column to set the default Java version.
Here, I chose 1 for OpenJDK 11.
Verify Java Version
Check the java version using the following command.
java -version
Output:
openjdk version "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)
The output may vary depending upon the package and the version you chose to be the default Java version.
Setup Environmental Variables
Java applications often require JAVA environment variables to be set in the system. For example, to run Java programs from anywhere, you need to set $JAVA_HOME and other variables to match your version of Java.
Create a new file under /etc/profile.d directory.
sudo nano /etc/profile.d/java.sh
Set variables based on the Java location and version for all users.
export PATH=$PATH:/usr/lib/jvm/jdk-11.0.12/bin/ export JAVA_HOME=/usr/lib/jvm/jdk-11.0.12/
To set the environment variables for a specific user, place the above variables in the ~/.bash_profile file.
Load the environments into the current session.
source /etc/profile.d/java.sh
Sumber: disini