If you’re working on a Debian-based system (Debian 10, 11, or 12) and need to install the latest Java Development Kit (JDK 23), follow these simple steps to get up and running in no time.
Steps to Install Java 23:
- Download the JDK 23 package:
Use thewget
command to download the JDK 23.deb
package from the official Oracle website.
wget https://download.oracle.com/java/23/latest/jdk-23_linux-x64_bin.deb
- Install the downloaded package:
Usedpkg
to install the JDK 23 package on your Debian system.
dpkg -i jdk-23_linux-x64_bin.deb
- Clean up:
Once the installation is complete, remove the downloaded.deb
file to keep your system clean.
rm jdk-23_linux-x64_bin.deb
After the installation, you can check if Java is successfully installed by running:
java -version
This will display the installed Java version, confirming that JDK 23 is correctly set up on your Debian system.
Start building your Java applications with the latest tools!
Switching Between Java Versions on Debian
Once you’ve installed multiple versions of Java on your Debian system (for example, Java 11, 12, 13, or the latest Java 23), you might need to switch between them depending on the requirements of your projects. Here’s how you can easily change the default Java version using the update-alternatives
command.
Steps to Switch Between Java Versions:
- Check the installed Java versions: First, check all the installed Java versions on your system by running:
update-alternatives --config java
This will list all available versions of Java on your system. You’ll see something like this:
There are 3 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/java-12-openjdk-amd64/bin/java 1122 manual mode
3 /usr/lib/jvm/java-23-oracle/bin/java 1233 manual mode
- Select the desired Java version: To change the Java version, choose the appropriate selection number. For example, if you want to switch to Java 23 (which in this example is
Selection 3
), type:
sudo update-alternatives --config java
Then, type the number of the Java version you want to use and press Enter.
- Verify the change: After selecting the version, you can verify that the system is now using the new Java version by running:
java -version
This should display the version of Java you’ve just selected, confirming that the switch was successful.
Example Output:
java version "23.0.1" 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 23.0.1+10-LTS)
Java HotSpot(TM) 64-Bit Server VM (build 23.0.1+10-LTS, mixed mode)
You can now easily switch between Java versions depending on the needs of your applications or projects.
Note: If you also need to switch the version for javac
, the Java compiler, you can use a similar command:
sudo update-alternatives --config javac
This flexibility makes it easy to manage multiple Java environments on a single machine without conflicts.