Java is a free, open source object-oriented programming language and one of the most widely used developed by Sun Microsystems. It is very popular for its robust features including, secure, distributed, multithreaded, portable and platform independent. There are two main implementations of Java OpenJDK and Oracle Java. OpenJDK is a free version of Java, while Oracle Java has some additional commercial features. You may use Oracle Java for non-commercial use, such as personal use and development use.
In this tutorial, we will learn the following:
How to install Java 11 on Debian 10. How to install Java 8 on Debian 10.
- How to install Oracle Java 11
- Debian 10
on Debian 10. Prerequisites A server running
- A root password is configured on the server.
Installing Java 11
on Debian 10
At the time of writing, OpenJDK 11 is the Long Term Support (LTS) release of Java. By default, it is available in the default Debian 10 repository. You can install it by simply running
the following command:apt-get update -y apt-get install default-jdk -y
Once the installation has completed successfully, you can check the Java version using
the following command:java -version
You should get the following result:
openjdk version “11.0.8” 2020-07-14 OpenJDK Runtime Environment (build 11.0.8+10-post-Debian-1deb10u1) OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Debian-1deb10u1, mixed mode, sharing)
If you want to install only Java Runtime Environment (JRE), run the following command:
apt-get install default-jre -y Install Java 8 on Debian 10 By default,
is not included in the default Debian 10 repository. You will need to add the Java repository on your system.
install apt-transport-https ca-certificates wget dirmngr gnupg software-properties-common -y
Then download and add the GPG key with the following command:
wget -qO – https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | apt-key add -Next, add the Java 8 repository using the following command:add-apt-repository -yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ Once the repository is added, update the repository and install Java 8 with the following command:apt-get update -y apt-get install adoptopenjdk-8-hotspot -y Once the installation has completed successfully, you can check the
Java version using the following command
You should get the following output:
openjdk version “1.8.0_265” OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_265-b01) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.265-b01, mixed mode) Installing Oracle Java
SE 11 on Debian 10
Oracle Java is a commercial version of Java with some additional features. You can use it for personal or development use only. By default, Oracle Java is not included in the Debian 10 repository. Therefore, you will need to create an Oracle account and download the desired version of Java from the Oracle website.
First, log in and visit the Oracle downloads page and locate the desired version of Java. In this case, we will install Java SE 11 LTS as shown below:
Then click the Download JDK button. You should see the page showing the available versions:
Select the jdk-11.0.8_linux-x64_bin.tar.gz package for Linux and download it to your system.
create a directory for Java installation
:mkdir -p /var/cache/oracle-jdk11-installer-local Then
copy the downloaded file to that directory
:cp jdk-11.0.8_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-installer-local/
Next, install the necessary dependencies on your system
with the following command:apt-get install software-properties-common gnupg2 -y
Then import and sign the key with the following command:
apt-key adv -keyserver keyserver.ubuntu.com -recv-keys EA8CACC073C3DB2A
You should get
the following output:Running: /tmp/apt-key-gpghome.jK1m3NXGgW/gpg.1.sh -keyserver keyserver.ubuntu.com -recv-keys EA8CACC073C3DB2A gpg: key EA8CACC073C3DB2A: public key “Launchpad PPA for Linux Uprising” gpg imported: Total number processed: 1 GPG: Imported: 1 Then add the
Java installer repository with the following command:add-apt-repository
ppa:linuxuprising/ then update the
repository and install Oracle
Java 11 SE with the following command:apt-get update -y apt-get install oracle-java11-installer-local -y After
the installed version of Java by running the following command:java -version
You should see the version of Java installed in the following output:
java version “11.0.8” 2020-07-14 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0. 8+10-LTS, mixed mode)
Set or change the default version
If you are using multiple versions of Java on your system. You can easily configure or change the default version of Java based on your development needs.
To change the default version of Java, run the following command:
update-alternatives -config java
You should see that there are three versions of Java installed on your system and the active version is Oracle Java 11.
There are 3 options for alternative java (providing /usr/bin/java). Selection path priority status – 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 automatic mode 1 /usr/lib/jvm/adoptopenjdk-8-hotspot-amd64/bin/java 1081 manual mode 2 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode * 3 /usr/lib/jvm/java-11-oracle/bin/java 1091 manual mode Click to keep the current option[*], or type the selection number:
Type the number of the installed version that you want to set as the default version and press Enter.
You will also need to do this for other Java commands, including javac, as shown below:
update-alternatives -config javac
JAVA_HOME environment variable
Some applications use the JAVA_HOME environment variable to determine the Java installation location. In this case, you will need to set the JAVA_HOME environment variable for your default version of Java.
First, you will need to locate the path of the Java installation. You can find it using
the following command:update-alternatives -config java
You should see the following output:
There are 3 options for alternative java (providing /usr/bin/java). Priority status of selection path – 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 automatic mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode * 2 /usr/lib/jvm/java-11-oracle/bin/java 1091 manual mode 3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
As you can see, the Java version path is as follows:
OpenJDK 11 is located in /usr/lib/jvm/java-11-openjdk-amd64/. Oracle Java is located in /usr/lib/jvm/
- OpenJDK 8 is located in /usr/lib/jvm/java-8-openjdk-amd64/.
Next, you need to copy the path of the desired Java version and add it to the /etc/environment:nano /etc/environment file Add the following
line for Oracle Java
11 version:JAVA_HOME=”/usr/lib/jvm/java-11-oracle/” Save and close the
file and activate the environment variable using the following command:
can verify the environment variable you have set using
the following command:echo $JAVA_home You should see the following
You should also read the following article
- How to Install Java Ubuntu 20.04
- Ansible for Absolute Beginners – Complete Guide