Edited 4 days ago by ExtremeHow Editorial Team
DebianJavaSoftware InstallationDevelopmentCLILinuxOpen SourceSystem AdministrationProgrammingIT
This content is available in 7 different language
Java is a popular programming language used in a wide range of applications, from web development to desktop applications. If you are using the Debian operating system and want to install Java, this detailed guide will help you with the process. We will cover the different versions of Java, how to select the right version for your needs, and the detailed steps to install Java on your Debian system. This guide is structured to provide you with understandable, detailed information on how to install Java, regardless of your previous experience with command-line interfaces or software installations.
Java is available in two different versions, let's understand their difference:
For our guide, we'll focus on installing OpenJDK as it's fully compatible and integrated with Debian's package management system. However, we'll also briefly explain how to install Oracle Java if that better aligns with your project's needs.
Before proceeding with the new Java installation, it is useful to check if Java is already installed on your system. You can do this by opening a terminal and typing:
java -version
If Java is installed, this command will return the current version number. If it is not recognized, you will see a message indicating that Java is not installed.
Debian repositories usually contain OpenJDK. Let's start installing it:
sudo apt update
sudo apt install default-jdk
This command will install the default Java Development Kit, which includes the Java Runtime Environment (JRE) required to run Java applications. Optionally, you can specify a different version:sudo apt install openjdk-<version>-jdk
Replace <version>
with the version number you want to install, such as openjdk-8-jdk
or openjdk-11-jdk
.java -version
The terminal should now display the installed version of OpenJDK.If you need to use Oracle Java instead of OpenJDK, here is the method for manual installation:
tar
command to extract the downloaded package. Go to your downloads directory (or wherever you downloaded the package) and run:tar -xzf jdk-<version>-linux-x64_bin.tar.gz
Replace jdk-<version>-linux-x64_bin.tar.gz
with the actual downloaded package name.sudo mv jdk-<version> /opt/
/etc/profile
in a text editor (you may need superuser privileges):sudo nano /etc/profile
Add the following lines to the file:export JAVA_HOME=/opt/jdk-<version> export PATH=\$PATH:\$JAVA_HOME/bin
Save and close the file, then apply the changes:source /etc/profile
java -version
Debian allows you to install multiple Java versions and easily switch between them with update-alternatives
utility. To configure the default Java version, follow these steps:
sudo update-alternatives --config java
Enter
after typing the number. This configuration also applies to other Java commands such as javac
, javadoc
, and keytool
.To make sure that Java is installed and working correctly, you can write a simple Java program. Use a text editor to create a file named HelloWorld.java
that has the following content:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
Use the following to compile the Java program:
javac HelloWorld.java
If compilation is successful, run the program:
java HelloWorld
The output should be Hello, World!
which confirms that your Java installation is successful.
Keeping your Java installation up to date is important for security and functionality. For OpenJDK updates, you can rely on the regular Debian update process:
sudo apt update sudo apt upgrade
These commands will update all existing packages including Java.
This guide walks you through installing Java on a Debian system, including both OpenJDK and Oracle Java. We discussed how to verify the installation, how to manage multiple Java versions, and how to test your installation with a simple Java program. Additionally, we explained how to keep your Java installation updated to ensure security and performance. By following this guide, you are well prepared to harness the potential of Java on your Debian machine.
If you find anything wrong with the article content, you can