Choose a different version or distribution
Introduction
Before we begin talking about how to install Java on Debian 10, let’s briefly understand – What is Java?
Java is a widely used programming language known for its versatility and compatibility. Developed by Sun Microsystems, it allows developers to write code that can run on different platforms, including computers, mobile devices, and embedded systems.
Java is an object-oriented language, making it easier to organize and structure code. With its robust libraries and tools, Java enables developers to create a wide range of applications, from simple desktop programs to complex enterprise systems. Its popularity and active community support make Java a solid choice for developers looking to build scalable and reliable software solutions.
In this tutorial, you will install Java on Debian 10. You can follow the same guidelines for other Ubuntu-based distribution, including Kubuntu, Linux Mint, and Elementary OS. We will also address some FAQs related to the Java installation.
Advantages of Java
- Platform Independence: Java code can run on multiple platforms without needing to be rewritten.
- Object-Oriented Programming: Java's OOP approach allows for modular and reusable code.
- Robust Libraries: Java offers a vast collection of pre-built libraries for various functionalities.
- Strong Community Support: Java has a large community of developers, providing resources, assistance, and frequent updates.
- Scalability and Reliability: Java's architecture and features make it suitable for building large-scale, robust, and stable applications.
Before You Begin
The only major distinction between OpenJDK and Oracle Java is that Oracle Java has some additional commercial features. The Oracle Java License only permits non-commercial uses of the program, such as private and development use.
The Java Runtime Environment (JRE) and Java Development Kit (JDK) are two separate Java packages included by default in the Debian 10 repositories. JRE, which comes with the Java virtual machine (JVM), classes, and binaries, allows Java programs to be run. Installing JDK, which includes JRE and the development/debugging tools and libraries required to create Java applications, is recommended for Java developers.
The general advice is to stick with the default OpenJDK (JDK 11) version if you are unsure about which Java package to install. You should review the application documentation because some Java-based applications might require a particular Java version.
Installing OpenJDK 11
The open-source Java Platform implementation OpenJDK 11 is the default Java development and runtime in Debian 10, Buster.
For the packages index to be updated and the OpenJDK 11 JDK package to be installed, run the following commands as root or a user with sudo privileges:
sudo apt update
sudo apt install default-jdk
You can check the Java version to see if the installation was successful once it is finished:
java -version
The final result should resemble this:
Output
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)
All done! You have now successfully installed Java on your Debian-based machine.
Installing OpenJDK 8
The official Debian Buster repositories do not currently have the prior Java LTS version 8 available.
We will activate the AdoptOpenJDK repository, which offers prebuilt OpenJDK packages.
1) Begin by updating the package list and installing the dependencies required to add a new repository over HTTPS:
sudo apt install apt-transport-https ca-certificates wget dirmngr gnupg software-properties-common
2) Use the wget command below to import the repository's GPG key:
wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
3) You should now configure the AdoptOpenJDK APT repository to your system:
sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
4) Use the following commands to update apt sources and install Java 8 after the repository has been enabled:
sudo apt update
sudo apt install adoptopenjdk-8-hotspot
5) Finally, check the Java version to confirm the installation:
java -version
The final result should resemble this:
Output
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b04, mixed mode)
Set the default version
If your Debian system has various versions of Java installed, you can check which one is the default by typing:
java -version
Use the update-alternatives
command to change the default version:
sudo update-alternatives --config java
The result will resemble the following:
Output
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/adoptopenjdk-8-hotspot-amd64/bin/java 1081 manual mode
2 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
Press <enter> to keep the current choice[*], or type selection number:
A list of all installed Java versions will be shown to you. Press Enter
after specifying the version number you want to be the default.
JAVA_HOME
Environment Variable
Some Java applications determine the location of the Java installation using the JAVA_HOME
environment variable.
Use the update-alternatives
command to determine the location of Java's installation before setting the JAVA_HOME
environment variable:
sudo update-alternatives --config java
These are the installation paths used in this example:
- OpenJDK 11 is located at
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
- OpenJDK 8 is located at
/usr/lib/jvm/adoptopenjdk-8-hotspot-amd64/bin/java
Open the /etc/environment
file once you have located the path of your desired Java installation:
sudo nano /etc/environment
Append the following line, assuming you want to set JAVA_HOME
to OpenJDK 11.
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
You can log out and back in again to make changes take effect on your current shell, or you can execute the source command described below:
source /etc/environment
Check to see if the JAVA_HOME
environment variable was set properly:
echo $JAVA_HOME
The location of the Java installation should be displayed:
Output
/usr/lib/jvm/java-11-openjdk-amd64
/etc/environment
. Add the line to the .bashrc
or any other configuration file that is loaded when the user logs in if you wish to set the JAVA_HOME
variable on a per-user basis.Uninstall Java
Like any other package installed using apt, Java can be uninstalled.
Run these commands, for instance, to uninstall the default-jdk
package:
sudo apt remove default-jdk
FAQs to Install Java on Debian 10 Linux
Can I install a specific version of Java on Debian 10 Linux?
Yes, you can install a specific version of Java on Debian 10 Linux. Instead of` default-jdk`, use openjdk-<version>-jdk
in the installation command. For example: sudo apt install openjdk-11-jdk
.
How can I switch between multiple Java versions on Debian 10 Linux?
To switch between multiple Java versions, use the update-alternatives command. Run: sudo update-alternatives --config java
and select the desired Java version from the list.
How do I check the installed Java version on Debian 10 Linux?
Open the terminal and run: java -version
Can I install Oracle Java on Debian 10 Linux?
Yes, you can install Oracle Java on Debian 10 Linux. However, it requires additional steps and manual configuration. It is recommended to use the default OpenJDK package provided by Debian.
Are there any alternatives to OpenJDK for Java on Debian 10 Linux?
Yes, there are alternative JDK implementations like Oracle Java, AdoptOpenJDK, and Amazon Corretto. However, OpenJDK is the default and widely used choice for Java on Debian.
How can I install Java Development Kit (JDK) only without the JRE on Debian 10 Linux?
To install only the JDK without the JRE, use the following command: sudo apt install default-jdk-headless
.
Can I install Java using a package manager like apt-get on Debian 10 Linux?
Yes, you can install Java using the apt package manager. Simply run the appropriate installation command, such as sudo apt install default-jdk
, as mentioned earlier.
Conclusion
We hope this detailed tutorial helped you to install Java on Debian 1o.
If you have any queries, please leave a comment below and we’ll be happy to respond to them.