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
🌐
Batsov
batsov.com › articles › 2021 › 12 › 10 › working-with-multiple-versions-of-java-on-ubuntu
Working with Multiple Versions of Java on Ubuntu | (think)
December 10, 2021 - Notice that pressing 0 means “auto-select the newest Java available” (in our case Java 11). You can now select Java 8 by pressing 2 and verify the command worked properly like this: You’ll need to repeat the above steps for javac (the Java compiler binary) as well: This much I already knew, even if I keep forgetting the exact name of update-alternatives, but today I learned something new as well. You can actually simplify the process a bit by using the specialized command update-java-alternatives:
Discussions

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
How do I switch between Java versions?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. 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/javahelp
13
11
March 20, 2023
How do I change default version of java from my terminal?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. 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/javahelp
11
2
December 22, 2023
how can I change the default Java version?
The AUR package should work fine. What's the output of archlinux-java status? More on reddit.com
🌐 r/linuxquestions
20
7
February 22, 2021
🌐
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 - Learn how to install multiple Java versions on Ubuntu, switch between them using update-alternatives, and configure JAVA_HOME for development environments.
🌐
Ubuntu Shell
ubuntushell.com › change-java-version
How to Change Java Version on Ubuntu (CLI and GUI)
November 16, 2025 - Now that the installation is complete, you can confirm once more the total version of Java installed on your system by running. ... Using the update-alternatives command-line tool. Using the G Alternatives GUI tool. Both methods are easy to follow, and most of the time, the command-line tool is recommended, as the GUI tool is just a front-end of the CLI tool. So, let's begin with the command-line tool. To change the version of Java using this method, first we will run the following command to find out the current default version of Java in use.
🌐
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 - Use the ‘update-alternatives –config javac’ command to select the default Java compiler from the installed versions. ... The headless version is useful for server environments where GUI functionality is not needed, reducing the resource footprint. How does Ubuntu choose the default Java version when multiple versions are installed?
🌐
Medium
salimsea.medium.com › how-to-change-java-version-in-ubuntu-a-step-by-step-guide-b12f96a12fae
How to Change JAVA Version in Ubuntu: A Step-by-Step Guide | by Salim Segaf Alqosam | Medium
July 23, 2024 - Enter the selection number of the Java version you wish to use * Finally, verify that the Java version has been updated: ... Switching between different Java versions on Ubuntu is a straightforward process. With this guide, you can easily manage and configure the Java environment to suit your development needs.
Find elsewhere
🌐
TecAdmin
tecadmin.net › switch-between-java-versions-on-ubuntu
How to Change default Java Version on Ubuntu
April 26, 2025 - Apply the changes: To reload current environment type: ... Check Java Compiler Version: Use javac -version to check the installed Java compiler version.
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - For that, we’ll need to invoke java: $ java --version openjdk 21.0.1 2023-10-17 OpenJDK Runtime Environment (build 21.0.1+12-Ubuntu-223.04) Now, if we need to change the Java version, we can use –set we can use –set:
🌐
Learn Ubuntu
learnubuntu.com › change-java-version
How to Change Java Version in Ubuntu
March 1, 2024 - Let's start with the first one. To change the Java version using the alternatives, use the --config flag and append java as shown here and it will list down available options to choose from:
🌐
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
🌐
Hostman
hostman.com › tutorials › switching-between-java-versions-on-ubuntu
Switching between Java Versions on Ubuntu Linux
Upon completing the installation, use the following command to confirm the correct and successful installation of the Java version: ... To switch between Java versions and set a default version on Ubuntu Linux, you can use the update-java-alternatives command.
🌐
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 - ✅ If post was helpful you could try following me on 📲twitter 💻 or check out my new blog ... if u still return error try with sudo and follwing command $ sudo update-alternatives --config java $ sudo update-alternatives --config javac ...
🌐
Linux Hint
linuxhint.com › change-java-version-linux
How to Change Java Version Linux – Linux Hint
To demonstrate how we switch between ... and an alternative version which is Java 17. To change the Java version in Linux, use the –config java option with the update-alternatives command:...
Top answer
1 of 8
151

Re your first question:

possibly you may be confusing that the webupd8 script is 0.5b. That is the version of the script - it doesnt refer to the java version.

Further to the setting of the javac version.

I suspect you need to explicitly give the path of the javac compiler

i.e.

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-6.31-oracle/bin/javac" 1

followed by:

sudo update-alternatives --config javac

With regards to setting up the java chrome plugin.

The master question:

How do I install Oracle JDK 6?

includes this information - since your folder structure is slightly different your link command should be:

ln -s /usr/lib/jvm/java-6.31-oracle/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/
2 of 8
104

See this; run

sudo  update-java-alternatives --list

to list off all the Java installations on a machine by name and directory, and then run

sudo  update-java-alternatives --set [JDK/JRE name e.g. java-8-oracle]

to choose which JRE/JDK to use.

If you want to use different JDKs/JREs for each Java task, you can run update-alternatives to configure one java executable at a time; you can run

sudo  update-alternatives --config java[Tab]

to see the Java commands that can be configured (java, javac, javah, javaws, etc). And then

sudo  update-alternatives --config [javac|java|javadoc|etc.]

will associate that Java task/command to a particular JDK/JRE.

You may also need to set JAVA_HOME for some applications: from this answer you can use

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

for JREs, or

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:jre/bin/java::")

for JDKs.

🌐
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 - Add this to your ~/.bashrc: # The Dynamic Architect's Java Home export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::") export PATH=$JAVA_HOME/bin:$PATH ... fosslinux@tuts:~$ source ~/.bashrc fosslinux@tuts:~$ echo $JAVA_HOME # Output: /usr/lib/jvm/java-17-openjdk-amd64 · For developers managing more than just Ubuntu-standard OpenJDK (e.g., GraalVM, Amazon Corretto, or specific versions of Kotlin/Maven), I ignore the system-level alternatives and use SDKMAN!.
🌐
ComputingForGeeks
computingforgeeks.com › home › switch default java version on ubuntu / debian
Switch Default Java Version on Ubuntu / Debian [Guide]
March 25, 2026 - Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-25-openjdk-amd64/bin/java 2511 auto mode 1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 2 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 3 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode 4 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 2111 manual mode 5 /usr/lib/jvm/java-25-openjdk-amd64/bin/java 2511 manual mode Press · to keep the current choice[*], or type selection number: Selection 0 (auto mode) always uses the highest-priority version. When you pick a specific number, the system enters manual mode and stays on your choice until you explicitly change it, even if a higher-priority version is installed later.
🌐
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`. Join Medium for free to get updates from this writer.
🌐
Reddit
reddit.com › r/ubuntu › noob question. how do i update to java 22 via terminal?
r/Ubuntu on Reddit: Noob question. How do I update to Java 22 via terminal?
October 12, 2025 -

SOLVED. Thanks!

Version Ubuntu 24.04.03 LTS, currently on Java 21, need 22 for my Minecraft server but sudo apt install openjdk-22-jdk gives error, unable to locate package. Just apt update just gives you version 21 as that's what seems to be on Ubuntu rn.

I suspect I need to download whatever .tar.gz for java, send it over via FTP, SSH back in and run it somehow but I haven't actually done that before and am not that technically savvy so hoping someone has a clearer tutorial then Google being like just reinstall Ubuntu so there's a GUI.

🌐
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 - After automating two new features ... version of the Java Runtime.” This error message, indicating a class file version mismatch, prompted me to explore solutions to swiftly switch between Java versions on my Ubuntu 22.04 machine....