Install Java on Debian 9 System - Step by Step Process ?

Java is one of the most popular programming language which is owned by Oracle and used to build different kinds of applications.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related OpenJDK queries.

In this context, we shall look into how to install Java on Debian 9 system. Here we will install various versions of the Java Runtime Environment (JRE) and the Java Developer Kit (JDK). Also, we will install OpenJDK from official packages from Oracle. 


How to Install OpenJDK on Debian ?

Before performing this Installation procedure, ensure that your are using a user account with sudo privileges on the Debian Machine.

OpenJDK 8 JDK is available to install from the standard Debian repositories.

i. Start by updating the package manager index using below command:

$ sudo apt update

ii. Now install Java by typing following command:

$ sudo apt install default-jdk

iii. Once the installation is finished you can confirm installation by checking version of jdk by:

$ java -version

It will show below output:

Output
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)


How to Install Specific Version of OpenJDK on Debian ?

OpenJDK stable version is available from the Debian Backports repository.

i. Start by adding Backports to your system software repository by running the following command:

$ echo 'deb http://ftp.debian.org/debian stretch-backports main' | sudo tee /etc/apt/sources.list.d/stretch-backports.list

ii. Once it is enabled you need to update package manager and then go ahead for install by executing.

$ sudo apt update

iii. You can install OpenJDK with your specified version. You just have to add version as per below syntax.

$ sudo apt install openjdk-[VERSION]-jdk

For example, if the stable version is OpenJDK 11. So we can install it using below command:

$ sudo apt install openjdk-11-jdk


How to Install Java From Oracle on Debian?

Oracle provides license permits only non-commercial use, for personal use and development use only. So before going to install it read the Oracle JDK License. Here we are going to install Java 11.

Now, Follow the below steps to install Java from Oracle.

i. Start by installing the necessary packages using below command:

$ sudo apt install dirmngr gnupg

ii. Now you need to enable repositories after importing the PPA public key by following commands:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A
echo ‘deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main’ | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list

iii. Once the repository is added and enabled, update the packages list index:

$ sudo apt update

iv. Next, run the below command to install package:

$ sudo apt install oracle-java11-installer

You will be prompted to accept and agree for the Oracle license. Accept it to continue installation.

v. Now, Check the installed version by running the following command:

$ java -version

It will show you output as below:

Output
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)


How to Set up default Java Version on Debian ?

If your Debian system have multiple version of Java then you can set default version as per your choice.

i. First, check the current default version by typing:

$ java -version

To change the default version use the update-alternatives system command as below:

$ sudo update-alternatives --config java
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-8-openjdk-amd64/jre/bin/java   1081      manual mode 
Press  to keep the current choice[*], or type selection number:

Here you can see list of all installed Java versions. Select appropriate selection number to set as default version.


How to Uninstall Java from Debian Linux System ?

You can uninstall the Java package same as other packages. For example, if you want to uninstall the default-jdk package simply run:

$ sudo apt remove default-jdk


[Need to configure Java on your Linux System? We can help you. ]

This article covers how to install and manage multiple Java versions on Debian 9 system. Also we described how to set default Java version and also how to uninstall Java once it is no longer needed.

Basically, the programming language Java and the Java virtual machine or JVM are used extensively and required for many kinds of software.


To install Default JRE/JDK Java on Debian.

1. First, update the package index.

$ sudo apt-get update

2. Next, install Java. Specifically, this command will install the Java Runtime Environment (JRE).

$ sudo apt-get install default-jre

When prompted, type y for yes to confirm the installation.

3. You can install the JDK with the following command:

$ sudo apt-get install default-jdk

Related Posts