How do I install Java 17 on Debian? The first Oracle Java 17 stable version was released on September 2021, and available to download and install. Java 17 comes with multiple improvements and bug fixes. The workstation users should consider to upgrade to this version.
This tutorial will help you to install Java 17 on Debian 11/10/9 systems using PPA and apt-get command. Ubuntu and Linux Mint users use the below link to install Java on their system.
- Read this => Install Java 8 LTS on Debian
- Read this => Install latest Java on Ubuntu & LinuxMint
Step 1 – Add PPA to System
The webupd8 team has built a Java installer package for Debian systems. You need to add that PPA repository to your system for installing Java 17 on Debian.
Create a new Apt configuration file /etc/apt/sources.list.d/java-17-debian.list, and edit in text editor.
sudo nano /etc/apt/sources.list.d/java.list
and add following content in it.
deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main deb-src http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main
Now import GPG key on your system for validating packages before installing them.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EA8CACC073C3DB2A
Step 2 – Install Latest Java on Debian
You are all set to start Java installation on Debian. Run the following commands to update apt-cache and then install Java 17 on the Debian system using the apt-get package manager.
sudo apt update
sudo apt install oracle-java17-installer
The installer will prompt for accept Oracle terms in order to continue Java installation on Debian. Accept the terms and complete setup.
Step 3 – Verify Java Installation
Finally, you have successfully installed Oracle Java on your Debian system. Let’s use the following command to verify the installed version of Java on your system.
Output:java version "17.0.1" 2021-10-19 LTS Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39) Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
Step 4 – Setup Java Environment
The Webupd8 PPA repository also provides a package to set environment variables, Install this package using the following command.
sudo apt install oracle-java17-set-default
The installer script set the environment variable for you. You can find these variables in /etc/profile.d/jdk.sh script.
Output:export J2SDKDIR=/usr/lib/jvm/java-17-oracle export J2REDIR=/usr/lib/jvm/java-17-oracle export PATH=$PATH:/usr/lib/jvm/java-17-oracle/bin:/usr/lib/jvm/java-17-oracle/db/bin export JAVA_HOME=/usr/lib/jvm/java-17-oracle export DERBY_HOME=/usr/lib/jvm/java-17-oracle/db
Step 5 – Switching Java Version
The Debian systems have installed multiple Java version’s can switch between them. The update-alternatives command line utility allows switching the Java version.
Run the following command to list selection list:
sudo update-alternatives --config java
This command will list all the installed Java version (Configured with update-alternatives). You will see the list like below:
Output: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 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode * 2 /usr/lib/jvm/java-17-oracle/bin/java 1091 manual mode Press
to keep the current choice[*], or type selection number: 2
Type a number to select Java version to set as default Java version on your Debian system.
Excellent tutorial. Very useful and very clear. Thanks a lot.