How to Install JAVA with APT on Debian 10

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
Update Debian 10 Packages

Update Debian 10 Packages

If you want to check if Java is installed, run the command.

$ java -version
Check Java in Debian 10

Check Java in Debian 10

Next, install OpenJDK 11 using the following command.

$ sudo apt install default-jdk
Install OpenJDK on Debian 10

Install OpenJDK on Debian 10

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.

Check OpenJDK Version in Debian 10

Check OpenJDK Version in Debian 10

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
Install Linux Uprising Java repository

Install Linux Uprising Java repository

Next, run the command to install dirmngr.

$ sudo apt install dirmngr
Install dirmngr on Debian 10

Install dirmngr on Debian 10

Next, import the signing key as shown.

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A
Install Signing Key

Install Signing Key

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
Install Oracle Java 12 on Debian 10

Install Oracle Java 12 on Debian 10

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

Oracle Java 12 Installer

Oracle Java 12 Installer

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

Accept License Agreements

Accept License Agreements

To check the version of Oracle Java 12 run.

$ java --version
Check Java in Debian 10

Check Java in Debian 10

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.

Set Java Default Version in Debian 10

Set Java Default Version in Debian 10

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
Verify Java Home Environment Variable

Verify Java Home Environment Variable

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.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

James Kiarie

This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.