Apt-get won't overwrite the existing java versions.

To switch between installed java versions, use the update-java-alternatives command.

List all java versions:

update-java-alternatives --list

Set java version as default (needs root permissions):

sudo update-java-alternatives --set /path/to/java/version

...where /path/to/java/version is one of those listed by the previous command (e.g. /usr/lib/jvm/java-7-openjdk-amd64).


Additional information:

update-java-alternatives is a convenience tool that uses Debian's alternatives system (update-alternatives) to set a bunch of links to the specified java version (e.g. java, javac, ...).

Answer from danzel on askubuntu.com
Discussions

Why is the default java package still only version 11
openjdk-18-jre is a package available for 21.10 and 22.04 If you need the official one from ORACLE I think you need to download it directly, as it may not be redistributable. More on reddit.com
🌐 r/Ubuntu
12
0
July 20, 2022
How do i change default java version on Linux Mint
Prism lets you pick your java runtime, and comes packaged with the appropriate openjre version. Also, you should use your package manager to manage packages instead of downloading them off random websites. I would normally say to refer to your distro's docs for help with this, but mint is pretty poorly documented IME. It has no pages about java in the user guide. More on reddit.com
🌐 r/linux4noobs
11
0
February 27, 2026
How to change java versions for different versions without deleting and installing.
Thanks for being a part of | r/Admincraft | ! | We'd love it if you also joined us on Discord! Join thousands of other Minecraft administrators for real-time discussion of all things related to running a quality server. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/admincraft
21
2
October 1, 2023
Noob question. How do I update to Java 22 via terminal?
wget https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.deb sudo dpkg -i jdk-25_linux-x64_bin.deb With Java anything higher than what you need is usually fine. Java 22 is just the minimum. More on reddit.com
🌐 r/Ubuntu
7
4
October 12, 2025
🌐
Hostman
hostman.com › tutorials › switching-between-java-versions-on-ubuntu
Switching between Java Versions on Ubuntu Linux
Ubuntu provides powerful tools to handle this, and one of the most effective methods is using the update-java-alternatives command. ... In this article, the process of switching between Java versions using updata-java-alternatives will be shown.
🌐
TecAdmin
tecadmin.net › switch-between-java-versions-on-ubuntu
How To Switch Between Different Java Versions on Ubuntu
April 26, 2025 - Open your terminal and type: ... This command will display the version details of the currently active Java. Switching between Java versions is as simple as changing the default version using update-alternatives.
🌐
LinuxConfig
linuxconfig.org › home › how to install and switch java versions on ubuntu linux
How to Install and Switch Java Versions on Ubuntu Linux
September 21, 2025 - Yes, you can install multiple Java versions on Ubuntu. Use the update-alternatives tool to manage and switch between them.
🌐
OneUptime
oneuptime.com › home › blog › how to install and switch java versions on ubuntu
How to Install and Switch Java Versions on Ubuntu
March 2, 2026 - # Install SDKMAN! curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" # Check version sdk version # List available Java versions sdk list java # Install a specific version sdk install java 21.0.2-tem # Temurin 21 sdk install java 17.0.10-tem # Temurin 17 sdk install java 11.0.22-tem # Temurin 11 # Switch in the current shell sdk use java 17.0.10-tem # Set as default sdk default java 21.0.2-tem # Show current version sdk current java · SDKMAN! also manages Maven, Gradle, Groovy, Kotlin, and other JVM ecosystem tools. # Full version info java -version # openjdk vers
Find elsewhere
🌐
OneUptime
oneuptime.com › home › blog › how to switch between java versions on ubuntu
How to Switch Between Java Versions on Ubuntu
March 2, 2026 - Switch both: sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac · With update-alternatives for system-wide defaults and environment ...
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - In this tutorial, we’ll see how to switch between multiple Java versions on major Linux distributions. update-java-alternatives is a tool that lets us manage different versions of Java on Debian and Ubuntu.
🌐
ComputingForGeeks
computingforgeeks.com › home › switch default java version on ubuntu / debian
Switch Default Java Version on Ubuntu / Debian [Guide]
March 25, 2026 - Ubuntu assigns priorities based on the version number: When you run --config and pick a specific version, the system enters manual mode. It stays on your choice even when you install a new JDK with a higher priority. To go back to auto mode: ... java - auto mode link best version is /usr/lib/jvm/java-25-openjdk-amd64/bin/java link currently points to /usr/lib/jvm/java-25-openjdk-amd64/bin/java · Switching java and javac individually is fine for two tools, but a JDK registers many alternatives: jar, javadoc, jshell, jlink, keytool, and more.
🌐
FOSS Linux
fosslinux.com › home › linux distributions › debian & ubuntu › ubuntu › how to switch java versions in ubuntu
How to Switch Between Java Versions in Ubuntu
April 24, 2026 - No. Java versions are loaded into memory when the application starts. Switching alternatives only changes which version will be used for the next process you spawn. Many modern distros (Ubuntu 24.04+) have moved Java 8 to the universe repository.
🌐
Laytoun' thoughts!
aboullaite.me › switching-between-java-versions-on-ubuntu-linux
Switching between Java Versions on Ubuntu linux
November 30, 2016 - If you're using Ubuntu Linux on your daily basis work, you've probably Java installed on your machine. Personally I prefer using Wepupd8 PPA to manage JAVA installation, it makes my life a lot more easier especially for updates. The Wepupd8 team didn’t add any binary for Oracle JAVA installation
🌐
GitHub
gist.github.com › ofhouse › b6cca8006329107fa0770a8dd87f45cf
Install and manage multiple Java SDK versions on Ubuntu · GitHub
java -version # Output for OpenJDK ... starting eclipse) you can easily switch between the different versions: sudo update-alternatives --config java > There are 2 choices for the alternative java (providing /usr/bin/ja...
🌐
FOSS Linux
fosslinux.com › home › linux distributions › debian & ubuntu › ubuntu › how to install & switch java versions on ubuntu (2026)
How to Install & Switch Java Versions on Ubuntu (2026)
June 1, 2026 - Need multiple Java versions on Ubuntu? I show you how to install OpenJDK 25, Java 21 LTS, and switch between them using update-alternatives and SDKMAN.
🌐
Ubuntu Shell
ubuntushell.com › change-java-version
How to Change Java Version on Ubuntu (CLI and GUI)
November 16, 2025 - The G Alternatives is a GUI frontend of the aforementioned update-alternatives command and works similarly to it, but this time you have a graphical interface to switch between different versions of Java. To install the G Alternative on Ubuntu, simply use the following command:
🌐
Faun
faun.pub › how-to-install-and-manage-multiple-jdk-versions-on-ubuntu-22-04-3de225c7d8c8
How to Install and Manage Multiple JDK Versions on Ubuntu 22.04 | by Achini Udari Jayasena | FAUN.dev() 🐾
November 1, 2024 - To change the active version of Java, type the number corresponding to the desired version. For example, to switch to Java 11, type `1` and press `Enter`.
🌐
Attacomsian
attacomsian.com › blog › change-default-java-version-ubuntu
How to change the default Java version on Ubuntu
February 17, 2020 - $ java -version openjdk version "11.0.2" 2019-01-15 OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.10.3) OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.10.3, mixed mode, sharing) That’s it. The default Java version is changed to OpenJDK 11. If you frequently switch between different Java versions, it is a good idea to write a short script to automate the process.
🌐
DEV Community
dev.to › harsvnc › how-to-change-your-java-and-javac-version-on-ubuntu-linux-1omj
How to change your Java and javac version on Ubuntu / Linux - DEV Community
October 19, 2021 - Maybe you wanted to check out the newest features of the new java version or you have some kind of old project that only works for some older version (yes i know java ist a wora language but anyway). ... There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-11-openjdk-armhf/bin/java 1061 auto mode 1 /usr/lib/jvm/java-11-openjdk-armhf/bin/java 1044 manual mode 2 /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java 1061 manual mode Press enter to keep the current choice[*], or type selection number:
🌐
Medium
medium.com › @waqas.waheed › switch-java-version-ubuntu-22-04-70804a46445a
Switch Java Version- Ubuntu 22.04 | by Waqas Waheed | Medium
April 17, 2024 - Switch Java Version- Ubuntu 22.04 In the realm of software development, staying abreast of the latest tools and technologies is imperative. Java, being one of the stalwarts in the programming world …
🌐
TecAdmin
tecadmin.net › managing-multiple-java-versions-on-ubuntu
Managing Multiple Java Versions on Ubuntu – TecAdmin
April 26, 2025 - Switch Java Versions: You can switch to any Java version anytime with the following command. Just replace the version you want to set as default java version: ... Managing multiple Java versions on Ubuntu doesn’t have to be a daunting task. With the right tools and commands, you can easily ...