How to Install Java on Debian 12: A Step By Step Guide
Java is a versatile and powerful programming language that enables users to create a wide range of applications, such as building games, creating web applications and designing embedded systems. Debian 12 is a robust and newly released Linux based operating system that provides a stable and reliable foundation for Java applications to thrive. Together with the Java and Debian system, you can unlock a world of possibility and innovation that can surely help people a lot. This can only be possible if you have installed Java on your Debian system.
In this guide, you will learn:
- How to Install Java on Debian 12 from apt Package Manager
- How to Remove Java from Debian 12 Installed Through apt Package Manager
- How to Install Java on Debian 12 from Deb File
- How to Remove Java from Debian 12 Installed Through Deb File
- How to Install Java on Debian 12 from SDKMAN
- How to Remove Java on Debian 12 Installed from SDKMAN
You can install Java on Debian 12 from:
- apt Package Manager
- deb Package
The previous Debian source repositories include a variety of Java versions, such as Java 8, Java 11, Java 17, Java 18 and Java 19. However, the latest Debian 12 source repository excluded other Java versions except Java 17. Thus, you will only be able to install Java 17 on Debian 12 from the apt command using the following steps:
Step 1: Update Debian Repository
Since, you are installing Java from the Debian repository, you must first ensure that it is updated, this can be done from the following command:
Step 2: Install Java on Debian 12 from apt
After the update, you can install Java on Debian 12 from the command given below:
Or you can use the following command to install Java 17 on Debian
Step 3: Check Java Version on Debian 12
To check Java is correctly installed on Debian, you can use the following command:
If you want to remove a specific version of Java installed from apt package manager, you can simply use the following syntax:
Note: Don’t forget to replace java_version with the version you installed on the Debian system from the apt package manager.
Java officially provided the deb package file that makes the installation pretty simple. You can download any version of Java and install it on Debian using the apt command.
If you are interested in installing the latest version of Java on Debian 12 from deb package, follow the below-given steps:
Step 1: Download Java deb Package
First, you will need to download the required Java deb package for Debian from the official website. If you want to directly download Java from the terminal, you can simply use the following command:
Step 2: Install Java deb Package on Debian 12
After downloading the deb package, you can use the apt installation command to install latest version of Java on Debian:
Step 3: Check Java Version on Debian
To verify the latest version of Java is installed on Debian, you can execute the following command:
If you have installed Java on Debian 12 through the deb file and want to remove it from the system, you can use the apt command to remove this version from the system. However, you must ensure which version you have installed on Debian through the deb package.
Since I have installed Java 21 on Debian, so the following command will be used for removing it from the system:
Besides installing the Java from Debian source repository or tar.gz file, you can also use the third-party application called SDKMAN to install Java on Debian 12. This can be done by following the steps given below:
Step 1: Install curl and zip on Debian
Ensure you have installed curl and zip on Debian, if it’s not, the following command can be executed that will install both on your system:
Step 2: Download and Install SDKMAN on Debian
You can then execute the following script on Debian terminal to download and install SDKMAN on the system:
Step 3: Initialize SDKMAN on Debian
To complete the SDKMAN installation on Debian 12, you have to run the onscreen command that appears right after completing the execution of the above command:
Note: The username in the above command will be different in your scenario.
Step 4: Check SDKMAN Version
You can confirm whether SDKMAN is successfully installed on Debian by running the following version command:
Step 5: Check the List of Java Versions on SDKMAN
To check the list of Java versions that can be installed on Debian 12 through SDKMAN, you can run the following command:
It will provide you with the list of different Java versions, Vendor and Identifier. Here, your concern is the Identifier. Pick your Vendor and note down the Identifier of that Vendor. Then quit the list using “q” button:
Step 6: Install Java on Debian from SDKMAN
You can then install Java on Debian 12 rom SDKMAN using the following command:
Here, I am installing Java 19 on Debian from SDKMAN:
Step 7: Check Java Version on Debian
To ensure Java installed from SDKMAN is your default Java version on Debian, you can run the following command to confirm it:
You cannot directly remove Java on Debian 12 from SDKMAN from the uninstall command because it doesn’t allow uninstalling the default Java version from the system. To remove Java on Debian, you must make the other Java version as your default one, this can be done from the following command:
Or use the update_alternatives method to switch to another Java version on Debian. Once this is done, you can remove Java on Debian installed from SDKMAN using the following command:
There are some applications that require a specific Java version that needs to be installed on your system. In that case, removing the current version of Java on the system is not an ideal choice. Don’t worry, you can use the following steps to use any Java version on your system without removing the previous ones:
Step 1: Check Current Java Version
Before using another Java version on Debian, you must confirm the current Java version you are using on the system, this can be done from the following command:
Step 2: Select Default Java Executable
Now, you must select the default Java executable on Debian from the list of currently installed Java versions on the system. You can do this from the command given below:
Step 3: Choose Java Version
You have to choose the Java version which you want to use on your system, do it by entering the selection number to keep the current Java version:
Step 4: Check Java Version
Once done, use the version command again to confirm the Java version is updated on Debian:
Tip: If you fail to remove Java from the Debian system, try switching to another Java version first, then try removing it again.
If there is a new update available for Java, you can install it again by downloading the updated deb file, targ.gz file or install Java from SDKMAN. Then use the step-by-step guidelines provided in the update-alternatives method of this guide to update Java on Debian.
If you are using older Debian version and are interested in installing another Java version from apt, you can simply specify the Java version in place of version_no:
Installing Java on Debian 12 will allow you to develop applications, games or design embedded systems. You can install Java on Debian directly from the apt package manager. However, this method will only install Java 17 version on your system. To install the latest Java version on Debian 12, you must download the tar.gz file from the Java official website. Then follow the step-by-step instructions provided in this guide to install Java on Debian. You can also install the SDKMAN tool on Debian that makes it easy for you to install any Java version on your system. The method selection for Java installation depends on your needs so choose the method wisely and start working with Java on the Debian system.