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.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

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

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

2 thoughts on “How to Install JAVA with APT on Debian 10”

  1. 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:

    $ echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list
    

    and it needs a sudo in front of the echo?

    Do you try the commands before publishing?

    Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

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