In this guide, you will learn:
How to Install and Use Multiple Java Versions on Debian
Bonus Method: How to Install Other Java Version on Debian
Contents
- 1 How to Install Java on Debian
- 2 How to Install Java on Debian from apt Package Manager
- 3 How to Remove Java from Debian Installed Through apt Package Manager
- 4 How to Install Java on Debian from Deb Package
- 5 How to Remove Java from Debian Installed Through Deb File
- 6 How to Install Java on Debian from SDKMAN
- 6.1 Step 1: Install curl and zip on Debian
- 6.2 Step 2: Download and Install SDKMAN on Debian
- 6.3 Step 3: Initialize SDKMAN on Debian
- 6.4 Step 4: Check SDKMAN Version
- 6.5 Step 5: Check the List of Java Versions on SDKMAN
- 6.6 Step 6: Install Java on Debian from SDKMAN
- 6.7 Step 7: Check Java Version on Debian
- 7 How to Remove Java on Debian Installed from SDKMAN
- 8 How to Use Multiple Java Versions on Debian
- 9 How to Update Java on Debian
- 10 Bonus Method: How to Install Other Java Version on Debian from apt
- 11 Conclusion
How to Install Java on Debian
You can install Java on Debian from:
- apt Package Manager
- deb Package
- SDKMAN
How to Install Java on Debian from apt Package Manager
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:
sudo apt update && sudo apt upgrade -y
Step 2: Install Java on Debian from apt
After the update, you can install Java on Debian from the command given below:
sudo apt install openjdk-17-jdk
Or you can use the following command to install Java 17 on Debian:
sudo apt install default-jdk
Step 3: Check Java Version on Debian
To check Java is correctly installed on Debian, you can use the following command:
How to Remove Java from Debian Installed Through apt Package Manager
If you want to remove a specific version of Java installed from apt package manager, you can simply use the following syntax:
sudo apt remove java_version -y
Note: Don’t forget to replace java_version with the version you installed on the Debian system from the apt package manager.
How to Install Java on Debian from Deb Package
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 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:
wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb
Step 2: Install Java deb Package on Debian
After downloading the deb package, you can use the apt installation command to install latest version of Java on Debian:
sudo apt install ./jdk-21_linux-x64_bin.deb
Step 3: Check Java Version on Debian
To verify the latest version of Java is installed on Debian, you can execute the following command:
How to Remove Java from Debian Installed Through Deb File
If you have installed Java on Debian 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:
How to Install Java on Debian from SDKMAN
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. 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:
sudo apt install curl zip
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:
curl -s “https://get.sdkman.io” | bash
Step 3: Initialize SDKMAN on Debian
To complete the SDKMAN installation on Debian, you have to run the onscreen command that appears right after completing the execution of the above command:
source “/home/username/.sdkman/bin/sdkman-init.sh”
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 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 from SDKMAN using the following command:
sdk install java Identifier
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:
How to Remove Java on Debian Installed from SDKMAN
You cannot directly remove Java on Debian 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:
sdkman use java Identifier
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:
sdk uninstall java 19-amzn
How to Use Multiple Java Versions on Debian
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:
sudo update-alternatives –config javac
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.
How to Update Java on Debian
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.
Bonus Method: How to Install Other Java Version on Debian from apt
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:
sudo apt install openjdk-version_no-jdk
Conclusion
Installing Java on Debian 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, 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.