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.

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.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

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

Leave a Reply to Ravi Saive Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.