In this blog post, you shall learn how to install Oracle Java 11 (OpenJDK 11) on Debian 12/11/10. Java is a widely used programming language for creating Web, mobile, and desktop applications. Java applications can be developed and deployed on servers, workstations, and IoT devices using the Java Platform.
JSR 388 in the Java community process designated Java 11 as the open-source reference implementation of version 11 of the Java SE Platform. JDK is a set of programming tools that includes JRE (Java Runtime Environment), Java, Javac, and Jar, among others.
Features of Java 11
Among the many features of Java 11 are:
- The String class in Java 11 gets a few new methods.
- New File Methods are now available.
- The Not Predicate Method is a method for determining whether or not something is true.
- An Arra is being collected.
- The java.net.http package’s new HTTP client.
- Lambda Syntax with Local Variables
- Access Control through Nest.
- Intrinsics for Aarch64 have been improved.
- A Garbage Collector with No Ops.
Install Java 11 (OpenJDK 11) on Debian 12/11/10
Using the following methods, you will be able to install Java 11 on Debian 12|11|10.
- Java SE Development Kit 11 (JDK 11)
- OpenJDK 11
1- Install Oracle Java 11 from Upstream repo on Debian 11
Packages for Java 11 can be found in the Debian 11 repository, as shown below:
$ sudo apt update -y
$ sudo apt-cache search openjdk | grep 11
libjax-maven-plugin - Using the xjc goal with OpenJDK 11+
openjdk-11-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-11-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-11-doc - OpenJDK Development Kit (JDK) documentation
openjdk-11-jdk - OpenJDK Development Kit (JDK)
openjdk-11-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-11-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-11-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-11-jre-zero - Alternative JVM for OpenJDK, using Zero
openjdk-11-source - OpenJDK Development Kit (JDK) source files
openjdk-11-jre-dcevm - Alternative VM for OpenJDK 11 with enhanced class redefinition
uwsgi-plugin-jvm-openjdk-11 - Java plugin for uWSGI (OpenJDK 11)
uwsgi-plugin-jwsgi-openjdk-11 - JWSGI plugin for uWSGI (OpenJDK 11)
uwsgi-plugin-ring-openjdk-11 - Closure/Ring plugin for uWSGI (OpenJDK 11)
uwsgi-plugin-servlet-openjdk-11 - JWSGI plugin for uWSGI (OpenJDK 11)
This means that the following packages can be installed from the OS APT repositories:
# Install openJDK JDK 11
sudo apt install openjdk-11-jdk
# Install OpenJDK JRE 11
sudo apt install openjdk-11-jre
Confirm Java version installed:
$ java -version
openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.13+8-post-Debian-1deb11u1, mixed mode, sharing)
2- Manually install OpenJDK 11 on Debian 12|11|10
The GNU General Public License version 2 applies to OpenJDK, which is a free and open-source implementation of the Java Platform, Standard Edition.
Install wget after updating your package list:
sudo apt update -y
sudo apt -y install wget
Before running the command below, make sure you have the most recent version of OpenJDK 11:
wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz
Using the tar command, extract the downloaded OpenJDK 11 archive file:
tar xvf openjdk-11+28_linux-x64_bin.tar.gz
Move the resulting folder to /opt directory.
sudo mv jdk-11*/ /opt/jdk11
Now, configure Java environment:
sudo tee /etc/profile.d/jdk.sh <<EOF
export JAVA_HOME=/opt/jdk11
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
Then source your profile file and check java command:
source /etc/profile.d/jdk.sh
Check Java version:
$ echo $JAVA_HOME
/opt/jdk11
$ java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
Install Java SE Development Kit 11 on Debian 12|11|10
Visit Java SE Development Kit 11 download’s page to download .deb file for installation.
Then install the DEB package downloaded above using the apt command:
sudo apt install ./jdk-11.0.26_linux-x64_bin.deb
Accept the installation prompt:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'jdk-11' instead of './jdk-11.0.26_linux-x64_bin.deb'
The following additional packages will be installed:
libasound2 libasound2-data
Suggested packages:
libasound2-plugins alsa-utils
The following NEW packages will be installed:
jdk-11 libasound2 libasound2-data
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 421 kB/145 MB of archives.
After this operation, 1,824 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Configure Java environment:
cat <<EOF | sudo tee /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/lib/jvm/jdk-11/
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
Source the file and confirm Java version installed:
$ source /etc/profile.d/jdk.sh
$ java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
Test Java installation on Debian 12|11|10
We’ll make a Hello World program to test Java 11.
cat > hello_world.java <<EOF
public class helloworld {
public static void main(String[] args) {
System.out.println("Hello World! Java 11 is awesome");
}
}
EOF
now, run the above code as follows:
$ java hello_world.java
Hello World! Java 11 is awesome
Setting Java Default Version
You can change your default Java as follows if you have multiple JDK versions installed.
sudo update-alternatives --config java
Running the above command, you might get the following error:
sudo: alternatives: command not found
The error above is because Java has not been added to the /usr/bin/java path. Run the following command to add:
sudo update-alternatives --install /usr/bin/java java /opt/jdk11/bin/java 1
Now change Java Default version:
$ 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-11-openjdk-amd64/bin/java 1111 auto mode
1 /opt/jdk-17.0.1+12/bin/java 1 manual mode
2 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /opt/jdk-17.0.1+12/bin/java to provide /usr/bin/java (java) in manual mode
Conclusion
Congratulations! Java 11 (OpenJDK 11) is installed on your Debian 11|10|9 system. Java coding is a lot of fun.
Other Guides: