Java is one of the most popular and widely used programming languages. Currently, a myriad of software applications depends on Java to function as required for instance Android Studio. Java comes in 3 different implementations: JRE, OpenJDK, and Oracle JDK.
Let’s briefly take a look at each of these in turn:
- JRE (Java Runtime Environment) – This is a set of software tools that are needed for the execution of Java applications.
- JDK (Java Development Kit) – is a development environment needed for the development of Java application & applets. It encompasses an interpreter, a compiler, an archiver, and other software tools.
- OpenJDK – is an open-source implementation of JDK. Oracle JDK is Oracle’s official version of JDK. Additionally, Oracle JDK ships with additional commercial features and also allows non-commercial use of the software such as personal development of Java applications.
Prerequisites
For this tutorial, you need to have a Debian 10 instance with a system user with Sudo privileges.
In this topic, you will learn how to install and set up Java with APT on Debian 10.
If unsure of which Java package to install, it’s highly recommended to go with OpenJDK 11 which is the default JDK in Debian 10.
How to Install OpenJDK 11 in Debian 10
To install OpenJDK 11 on Debian 10, login as a regular user with sudo privileges and update the system packages as shown.
$ sudo apt update

If you want to check if Java is installed, run the command.
$ java -version

Next, install OpenJDK 11 using the following command.
$ sudo apt install default-jdk

You can now verify the OpenJDK version by running.
$ java -version
If the installation went well without a hitch, you should get the output below.

Let’s now see how to install Oracle Java.
How to Install Oracle Java 12 on Debian 10
To successfully install Oracle Java 12 on Debian 10 buster, you need to append the Linux Uprising Java repository as shown.
$ sudo echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list

Next, run the command to install dirmngr.
$ sudo apt install dirmngr

Next, import the signing key as shown.
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A

After successfully adding the Linux Uprising repository, run the commands below to install Oracle Java 12 on Debian 10.
$ sudo apt update $ sudo apt install oracle-java12-installer

A pop-up window will be displayed. Hit on the TAB button to navigate to the ‘OK’ option and press ENTER.

In the next windows, navigate to the ‘yes’ option with the cursor keys and hit ENTER to accept the license agreements.

To check the version of Oracle Java 12 run.
$ java --version

Great! This confirms that we have successfully installed Oracle Java 12.
How to Set JAVA_HOME Environment Variable in Debian 10
In some scenarios, there may be more than one version of JAVA installed on your system. If you need to set the default version, for instance, in this case, Oracle Java 12, use the command below.
$ sudo update-alternatives --config java
In the output as seen below, type the number corresponding to the version of Java you’d like to set as default and hit ENTER.

Now we need to set the JAVA_HOME environment variable. To achieve this, open the /etc/environment file.
$ sudo vim /etc/environment
Add the line below.
JAVA_HOME="/usr/lib/jvm/java-12-oracle"
Next, Save and exit the text editor. Finally, issue the source command as follows.
$ source /etc/environment
To confirm the Java environment variable setting, run the command.
$ echo JAVA_HOME

Conclusion
You’ve come to the end of this tutorial. In this guide, you learned how to install Java in Debian 10 and set the JAVA_HOME variable. Feel free to get back to us with your feedback.
You forget a
/
here, it must be/etc
.$ echo “deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main” | sudo tee etc/apt/sources.list.d/linuxuprising-java.list
The correct command is:
and it needs a sudo in front of the echo?
Do you try the commands before publishing?
@Anton,
Corrected the command in the article, as pointed by you.
Yes, no need for
sudo
in front of echo…