In this tutorial, I explain how to install a current Java on Debian. Java is one of the most popular programming languages for creating different types of applications and systems. Applications developed in Java are scalable, flexible and maintainable.
However, there are two different Java packages, Java Runtime Environment (JRE) and Java Development Kit (JDK). If you only want to run Java programs, you need JRE. If you're a Java developer, you need a JDK that includes JRE and development / debugging tools and libraries.
There are different implemetations, such as OpenJDK, which can be easily installed via Debian's package manager. But then there is also Oracle Java, which is mostly up to date and has commercial features. The installation of the latter should be documented here.
However, before you just copy the commands, check that there is not already a more recent version of Java and use that data instead of the data published here.
Use the following chain of commands to get the Java archive.
curl -L -b "oraclelicense=a" -O download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.1_linux-x64_bin.tar.gz
This command is convenient because it automatically accepts the Oracle license and thus can be included in a script.
If this directory does not already exist, create it. To then extract the tar file there.
tar -xzvf jdk-11.0.1_linux-x64_bin.tar.gz -C /usr/lib/jvm
Then the alternatives are created and set:
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-11.0.1/bin/java" 1500
update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-11.0.1/bin/javac" 1500
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk-11.0.1/bin/javaws" 1500
update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk-11.0.1/bin/jar" 1500
update-alternatives --set "java" "/usr/lib/jvm/jdk-11.0.1/bin/java"
update-alternatives --set "javac" "/usr/lib/jvm/jdk-11.0.1/bin/javac"
update-alternatives --set "javaws" "/usr/lib/jvm/jdk-11.0.1/bin/javaws"
update-alternatives --set "jar" "/usr/lib/jvm/jdk-11.0.1/bin/jar"
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
If several Java versions exist on your system, the standard version can be adapted as shown below.
update-alternatives --config java
The screen output prompts you to confirm the number whose Java version you want to set as default.