1# install default JDK
2sudo apt install default-jdk
3# install default JRE
4sudo apt install default-jre
5# install specific JDK version
6sudo apt install openjdk-17-jdk
7# install specific JRE version
8sudo apt install openjdk-17-jre
1// for debian & debian based linux distributions
2 sudo su or su -
3 echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu focal main" | tee /etc/apt/sources.list.d/linuxuprising-java.list
4 apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A
5 apt-get update
6 Ctrl + D or exit
7// for Ubuntu, Linux Mint, Pop!_OS or Zorin Os
8 sudo add-apt-repository ppa:linuxuprising/java
9 sudo apt update
10
11// Now you can install Oracle JDK 16 on Debian / Ubuntu and Linux distributions based on these:
12 //Install and make Oracle JDK 16 the default JDK version:
13 sudo apt install oracle-java16-installer --install-recommends
14 //Install but don't make Oracle JDK 16 the default JDK version:
15 sudo apt install oracle-java16-installer --no-install-recommends
16
17//To check which Java version is set as default on your system
18 java -version or javac -version
19
20//To accept the Oracle Java 16 license automatically
21 echo oracle-java16-installer shared/accepted-oracle-license-v1-2 select true | sudo /usr/bin/debconf-set-selections
22 //If that doesn't work, also try this command:
23 echo oracle-java16-installer shared/accepted-oracle-licence-v1-2 boolean true | sudo /usr/bin/debconf-set-selections