
In this tutorial, we will walk through install Java on Debian 10 Buster. Java is one of the most popular programming languages used to build scalable and flexible applications and systems.
Java comes in two different implementations OpenJDK and Oracle Java. Oracle java provides commercial features. It’s license allows only non-commercial use of software, for personal use or development use.
Java Runtime Environment (JRE) and Java Development Kit (JDK) are two different versions included in default Debian 10 repositories.
- JRE (Java Runtime Environment) – It includes a set of software tools, classes and binaries that require for the execution of Java applications.
- JDK (Java Development Kit) – It is development environment and needed for the development of Java application. It includes an interpreter, a compiler, an archiver, and other software tools.
- OpenJDK – It’s an open-source implementation of JDK. If you are not sure which Java package to install then you should stick to the default OpenJDK.
Prerequisites
You should have a Debian 10 instance with a system user with sudo privileges.
Installing OpenJDK 11
In Debian 10, the default Java development and runtime platform is OpenJDK 11. Run the below commands to update the packages index and install OpenJDK 11 JDK package.
sudo apt update
sudo apt install default-jdk
On the completion of installation, you can verify it by checking Java version:
java -version
It should show output as below:
openjdk version "11.0.3" 2019-04-16 OpenJDK Runtime Environment (build 11.0.3+7-post-Debian-5) OpenJDK 64-Bit Server VM (build 11.0.3+7-post-Debian-5, mixed mode, sharing)
Install Oracle Java on Debian 10
At first, you need to install some required packages on your Debian system. Perform the following commands:
sudo apt update
sudo apt install wget libasound2 libasound2-data
After that, download the latest Java SE Development Kit 13 LTS debian file release from its official download page. Also, you can download it using command-line as given below:
wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/13.0.1+9/cec27d702aa74d5a8630c65ae61e4305/jdk-13.0.1_linux-x64_bin.deb
Now, use the Debian package installer utility (dpkg)
to install a downloaded Java package on your system. Run the following command:
dpkg -i jdk-13.0.1_linux-x64_bin.deb
That’s it! Java 13 is installed on your system. You can verify by checking version of Java:
java -version
It should show something like this:
java version "13.0.1" 2019-10-15 Java(TM) SE Runtime Environment (build 13.0.1+9) Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)
Great! This confirms that we have successfully installed Oracle Java 13.
Set the default Java version
If you have multiple Java versions installed on your Debian system you can set as the default which you want. First of all, check the current default version by typing:
java -version
To change the default version use the update-alternatives
command:
sudo update-alternatives --config java
The output will show something like this:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/jdk-13.0.1/bin/java 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number:
It will show the installed Java versions. Select the version which you want to set as default by entering number and hit Enter
key.
JAVA_HOME Environment Variable
The JAVA_HOME
environment variable holds the Java installation location which used by the Java applications.
At first, use update-alternatives
command to find where the Java versions are installed:
sudo update-alternatives --config java
It will show the path where Java is installed. In this example the installation paths are as follows:
- OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java
- Java 13 is located at /usr/lib/jvm/jdk-13.0.1/bin/java
Now, open the /etc/environment
file by typing:
sudo nano /etc/environment
To set Java 13 as default, set Java 13 installation path to JAVA_HOME
as given below, at the end of file:
JAVA_HOME="/usr/lib/jvm/jdk-13.0.1"
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
You should see the path to the Java installation:
/usr/lib/jvm/jdk-13.0.1
Uninstall Java
You can uninstall Java like any other package installed with apt:
For example, to uninstall the default-jdk
package simply run:
sudo apt remove default-jdk
Conclusion
The latest LTS version of OpenJDK is available in the default Debian 10 Buster repositories and the installation is a simple and straightforward task. You learned how to install different java version on Debian 10 Buster.
If you have any query or suggestion, feel free to leave a comment.
Leave a Reply