This is a step by step guide on how to quickly install Java 17 LTS on Debian 12.
Table of Contents
Installing Java 17 LTS on Debian 12
OpenJDK vs Oracle JDK
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.
JDK vs JRE
JRE stands for Java Runtime Environment while JDK stands for Java Development Kit.
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.
Install OpenJDK 17 LTS on Debian 12
OpenJDK 17 packages are available on the default Debian 12 Universe repositories.
apt update
apt-cache search openjdk | grep 17
Sample output;
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-17 - Java plugin for uWSGI (OpenJDK 17)
uwsgi-plugin-jwsgi-openjdk-17 - JWSGI plugin for uWSGI (OpenJDK 17)
uwsgi-plugin-ring-openjdk-17 - Closure/Ring plugin for uWSGI (OpenJDK 17)
uwsgi-plugin-servlet-openjdk-17 - JWSGI plugin for uWSGI (OpenJDK 17)
To install OpenJDK 17 LTS on Debian 12, execute the commands below;
apt install openjdk-17-jdk
Check Java Version on Debian
Confirm the version;
java --version
openjdk 17.0.7 2023-04-18
OpenJDK Runtime Environment (build 17.0.7+7-Debian-1deb12u1)
OpenJDK 64-Bit Server VM (build 17.0.7+7-Debian-1deb12u1, mixed mode, sharing)
How to Set Default Java Version on Debian 12
If you have multiple versions of Java installed and want to set either Java 17 LTS as the default, run the command below;
sudo update-alternatives --config java
If there are other versions of Java installed, the command will list them and their system paths.
You will also see a current default Java version with an asterisk (*).
Choose any number with the respective version of Java you need to make default, type the number and press ENTER to set that specific version as default.
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.7 2023-04-18
OpenJDK Runtime Environment (build 17.0.7+7-Debian-1deb12u1)
OpenJDK 64-Bit Server VM (build 17.0.7+7-Debian-1deb12u1, 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:/bin/java::"
Sample output;
/usr/lib/jvm/java-17-openjdk-amd64
Next, update the /etc/environment file to load the environment variables.
echo "JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" >> /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
Well, you are good to go. That is all on how to install Java 17 LTS Debian 12.
See other related guides by following the links below;