How to Install JAVA with APT on Debian 10
Abstract: run the commands below to install Oracle Java 12 on Debian 10. $ sudo apt updateyou should get the output below. Check OpenJDK Version in Debian 10 Le
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.
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 10To install OpenJDK 11 on Debian 10, login as a regular user with sudo privileges and update the system packages as shown.
$ sudo apt updateUpdate Debian 10 Packages
If you want to check if Java is installed, run the command.
$ java -versionCheck Java in Debian 10
Next, install OpenJDK 11 using the following command.
$ sudo apt install default-jdkInstall 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 10Let’s now see how to install Oracle Java.
How to Install Oracle Java 12 on Debian 10To 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.listInstall Linux Uprising Java repository
Next, run the command to install dirmngr.
$ sudo apt install dirmngrInstall dirmngr on Debian 10
Next, import the signing key as shown.
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2AInstall 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-installerInstall 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 InstallerIn the next windows, navigate to the ‘yes’ option with the cursor keys and hit ENTER to accept the license agreements.
Accept License AgreementsTo check the version of Oracle Java 12 run.
$ java --versionCheck Java in Debian 10
Great! This confirms that we have successfully installed Oracle Java 12.
How to Set JAVA_HOME Environment Variable in Debian 10In 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 10Now 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_HOMEVerify 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.