Read in 3 minutes
How to install Java on Debian 9
In this tutorial, we will walk through installing Java on Debian 9. Java is one of the most popular programming languages used to build different kinds of applications and systems. Applications developed in Java are scalable, flexible and maintainable.
There are two different Java packages, Java Runtime Environment (JRE) and the Java Development Kit (JDK). If you only want to run Java programs then you need JRE and if you are Java developer then you will need JDK which includes JRE and development/debugging tools and libraries.
There are also two different implementations of Java, OpenJDK and Oracle Java with almost no differences between them except that Oracle Java has a few additional commercial features.
If you are not sure which Java implementation and version to use, the general recommendation is to stick with the default OpenJDK version available on Debian 9.
OpenJDK, the open source implementation of the Java Platform is the default Java development and runtime in Debian 9.
The installation is simple and straightforward.
Install OpenJDK 8 JDK
sudo apt install default-jdk
Install OpenJDK 8 JRE
sudo apt install default-jre
Install Oracle Java
In this section we will go through the steps of installing Oracle Java from the WebUpd8 repository. The WebUpd8 package will automatically download and install Oracle JDK for us.
To be able to add new repositories with the
add-apt-repository command, first we need to install the install the
sudo apt install software-properties-common dirmngr
Now we can add the WebUpd8 repository and install Oracle Java:
sudo add-apt-repository "deb http://ppa.launchpad.net/webupd8team/java/ubuntu yakkety main" sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C2518248EEA14886
Install Oracle Java 8
apt-get install oracle-java8-installer
Set the default version
We can check the version of our default Java, with:
java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
If we have multiple Java versions installed on the server we can change the default version using the
sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode 1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode * 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode Press <enter> to keep the current choice[*], or type selection number:
Enter the number when prompted and press
If for any reason you want to uninstall the Java package, you can unistall it as any other package installed with
apt. For example if you want to uninstall the
default-jre package simply run:
sudo apt remove default-jre
Now that you have learned how to install and manage different Java versions on your Debian server, your next step could be to install one of the many applications which runs on Java, such as Tomcat,, JBoss/WildFly, Jetty, Glassfish, WebLogic, Cassandra, Jenkins ..etc
If you have any questions feel free to leave a comment.