Install Java 11|Java 17|Java 18 on Debian 11

|
Last Updated:
|
|

Follow through this tutorial to quickly learn how to install Java 11|Java 17|Java 18 on Debian 11.

Install Java 11|17|18 on Debian 11

There are two versions of Java; OpenJDK and Oracle JDK;

While both are products of Oracle, OpenJDK is an opensource version while Oracle JDK is a enterprise product that requires a commercial license to use.

Install OpenJDK 11|OpenJDK 17|OpenJDK 18 on Debian 11

OpenJDK 11|OpenJDK 17|OpenJDK are available on the default Debian 11 Universe repositories.

apt-cache search openjdk | egrep '11|17|18'

Sample output;


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
openjdk-17-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-17-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-17-doc - OpenJDK Development Kit (JDK) documentation
openjdk-17-jdk - OpenJDK Development Kit (JDK)
openjdk-17-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-17-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-17-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-17-jre-zero - Alternative JVM for OpenJDK, using Zero
openjdk-17-source - OpenJDK Development Kit (JDK) source files
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)

There are no Java 18 packages available on the default Debian 11 repositories, as of this writing.

If you want, you can install just JRE or JDK.

“JDK is a superset of JRE, and contains everything that is in JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications. JRE provides the libraries, the Java Virtual Machine (JVM), and other components to run applets and applications written in the Java programming language”.

We will install OpenJDK in this tutorial;

Install OpenJDK 11 on Debian 11

To install OpenJDK 11 on Debian 11, execute the commands below;

apt update
apt install openjdk-11-jdk

Confirm the version;

java --version
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-post-Debian-1deb11u1, mixed mode, sharing)

Install OpenJDK 17 on Debian 11

To install OpenJDK 17 on Debian 11, execute the commands below;

apt update
apt install openjdk-17-jdk

Confirm the version;

java --version
openjdk 17.0.3 2022-04-19
OpenJDK Runtime Environment (build 17.0.3+7-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 17.0.3+7-Debian-1deb11u1, mixed mode, sharing)

Install OpenJDK 18 on Debian 11

As of this writing, Java 18 is not available on the default Debian 11 repositories. Thus, to install OpenJDK 18 on Debian 11;

Download Java 18 DEB Binary from downloads page and install as follows.

apt install wget -y
wget https://download.oracle.com/java/18/latest/jdk-18_linux-x64_bin.deb
apt install ./jdk-18_linux-x64_bin.deb

Confirm the version;

java --version
java 18.0.1.1 2022-04-22
Java(TM) SE Runtime Environment (build 18.0.1.1+2-6)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.1.1+2-6, mixed mode, sharing)

How to Set Default Java Version on Debian 11

If you have multiple versions of Java installed and want to set either Java 11|Java 17|Java 18 as the default, run the command below;

sudo update-alternatives --config java

Sample output;


There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/jdk-18/bin/java                  1811      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
  3            /usr/lib/jvm/jdk-18/bin/java                  1811      manual mode

Press  to keep the current choice[*], or type selection number:

From the output above, you can see that Java 18 is the current default Java version set.

For example, I would enter number 2 if i want to set Java 17 as the default version.


There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/jdk-18/bin/java                  1811      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
* 3            /usr/lib/jvm/jdk-18/bin/java                  1811      manual mode

Press  to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-17-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode

To set another default version, rerun the sudo update-alternatives --config java command choose the enter the number of your selection and press ENTER from the above command output.

If Java 18 path doesn’t show up in update-alternatives output, then install it as follows;

for i in java javac; do update-alternatives --install /usr/bin/$i $i /usr/lib/jvm/jdk-18/bin/$i 1811; done

Then when you list again, it should be available;

update-alternatives --list java

Set JAVA HOME Environment Variable

Next you can set Java home environment variable of your Java selection by updating the path to the Java version.

For example, current version of Java selected;

java --version
openjdk 17.0.3 2022-04-19
OpenJDK Runtime Environment (build 17.0.3+7-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 17.0.3+7-Debian-1deb11u1, mixed mode, sharing)

The path can be obtained by rerunning the command above or by just running the command below;

readlink -f /usr/bin/java | sed "s:jre/bin/java::"

Sample output;

/usr/lib/jvm/java-17-openjdk-amd64/bin/java

Next, update the /etc/environment file to load the environment variables.

echo "JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/bin/java" >> /etc/environment
source /etc/environment

To confirm the Java home environment variable setting, run the command below;

echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64/bin/java

Well, you are good to go. That is all on how to install Java 11|Java 17|Java 18 Debian 11.

See other related guides by following the links below;

Install Java 11|Java 17|Java 18 on Rocky Linux

Install Java 11|Java 17|Java 18 on Ubuntu 22.04

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment