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

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 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
how to update java jdk to the latest version in linux 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://imgur.com/a/fgoFFis ) 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
5
1
July 9, 2021
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
🌐
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:
🌐
MTU Service Desk
servicedesk.mtu.edu › TDClient › KB › ArticleDet
Changing Java versions (Linux) - Service Desk
These scripts are located at the following location: `/opt/java-selection/` In order to activate a Java version, run the script corresponding to the version you would like to work with, then reload or resource your terminal: For example the ...
🌐
Super User
superuser.com › questions › 1419753 › how-to-change-java-jdk-version
How to change java jdk version? - Super User
I want to install the new 11.0.02 java jdk. I tried to use this link: first source and afterwards this: second source Now, using cmd, I run these two commands: java -version ==> the older versio...
🌐
Linux Hint
linuxhint.com › change-java-version-linux
How to Change Java Version Linux – Linux Hint
To change the Java version in Linux, use the –config java option with the update-alternatives command:
🌐
MTU Service Desk
servicedesk.mtu.edu › TDClient › 1801 › Portal › KB › ArticleDet
Article - Changing Java versions (Linux)
These scripts are located at the following location: `/opt/java-selection/` In order to activate a Java version, run the script corresponding to the version you would like to work with, then reload or resource your terminal: For example the ...
Find elsewhere
🌐
Ubuntu Shell
ubuntushell.com › change-java-version
How to Change Java Version on Ubuntu (CLI and GUI)
November 16, 2025 - As you can see, we had two different ... version, whether it's Java 21 or any other, simply run the update-alternatives command with the --config flag and append java to it, as shown....
🌐
Reddit
reddit.com › r/linux4noobs › how do i change default java version on linux mint
r/linux4noobs on Reddit: How do i change default java version on Linux Mint
February 27, 2026 -

I downloaded new fabric mod loader in minecraft and it seems to be that i have problem with my Java version, I was using JDK 21 instead of JDK25.

So i updated by downloading open jdk 25 from Oracle.
i installed .deb file

and when i typed " java --version " in terminal it was still showing that i'm using Java 21

then to change version i used command

sudo update-alternatives --config java

and

sudo update-alternatives --config javac

and selected JDK-25

i closed terminal, opened again and did " java --version" and still it's stuck at Java 21.

am I doing something wrong ?

can someone please help me.

Top answer
1 of 5
8
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.
2 of 5
2
There is a tool often found on Debian and Ubuntu specifically for java versions called "update-java-alternatives" part of the "java-common" package. Example usage: update-java-alternatives --list sudo update-java-alternatives --set java-1.25.0-openjdk-amd64 java --version Whichever tool you use, be sure to call it with --set so the links are created. See this tool is rather simple in principle, you have a pool of packages (often just various versions of the same package) categorized by purpose, then you can specify which one to make "visible" on your path by linking. When you type in "java", you don't really end up running the java executable directly, but a link to the appropriate version you deemed default. Another example would be /usr/bin/editor or simply just run "editor" as /usr/bin is on the path. Now, if you don't like the default "editor" you can swap it out with update-alternatives. When you install a package it may install itself as an alternative for a specific usage. You have installed the downloaded deb file, which I assume should've done just that, so when you list the java alternatives jdk 25 should show up. If it doesn't, that's a different matter, but you can add it manually with the --install flag. https://www.man7.org/linux/man-pages/man1/update-alternatives.1.html Option 2. If you - for whatever reason - don't see value in the above, obviously you can just patch your ~/.bashrc (and .profile for login shells) to add the location to the Java version you want to make "default", for example: export PATH=$PATH:/usr/lib/jvm/java-21-openjdk-amd64/bin But again... alternatives is already nice and useful.
🌐
Sticsrpacks
sticsrpacks.github.io › SticsOnR › articles › Changing_java_version_linux.html
Changing Java version procedure under linux • SticsOnR
After the Java 17 installation, and if it is not the default version known by the system, switching to this version can be done with a script like the following one. It can be ran either from R or a shell terminal. #!/bin/bash # Changing latest installed Java version to Java version 11 echo "The current Java version is : " java -version version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}') if !
🌐
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.
🌐
Xmodulo
xmodulo.com › change-default-java-version-linux.html
How to change default Java version on Linux
First, check available Java versions on your Linux system by using update-alternatives command: ... In this example, there are four different Java versions that are installed: OpenJDK JRE 1.6, Oracle Java JRE 1.6, OpenJDK JRE 1.7 and Oracle Java JRE 1.7. The default Java version is currently ...
🌐
Medium
medium.com › @mariomendonca › how-to-easily-install-and-change-java-version-on-linux-and-macos-0a3131c58f7d
How to easily install and change Java version on Linux and MacOS | by Mario Mendonça | Medium
January 9, 2024 - I didnt set as default just to show how to do it after, but it's the easiest way. ... You have two options about changing the version. Change the version in a specific terminal. In this case you should use the command sdk use java {VERSION}
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.

🌐
LinuxVox
linuxvox.com › blog › change-java-version-linux
Changing Java Version on Linux: A Comprehensive Guide — linuxvox.com
Before changing the Java version, you need to know the currently installed Java version. You can use the following commands: # Check Java version java -version # Check JDK version javac -version · To check the JAVA_HOME environment variable, use the following command: ... Most Linux distributions provide package managers to install Java.
🌐
Medium
hasangalakdinu.medium.com › how-to-switch-java-versions-in-linux-using-aliases-9902281d1471
How to switch Java versions in Linux(using aliases) | by hasanga lakdinu | Medium
February 22, 2021 - # for java 11 export JAVA_HOME="/YOUR-PATH-TO-JDK/jdk-11.0.10" export PATH=:$JAVA_HOME/bin:$PATH`java -version`
🌐
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 - I realized I had forgotten (once again) how to switch between multiple Java versions on Ubuntu (Debian), so I’ve decided to write a short article that would help me remember this better.1 · You can easily install multiple versions of Java on Ubuntu via apt: Typically the newest version of Java you install will become the default, but you can easily change this:
🌐
Itsubuntu
itsubuntu.com › how-to-change-java-version-in-linux-2023
How To Change Java Version In Linux [2023] | Technology News Information & Jobs
January 30, 2023 - Now you need to enter the number in the confirmation prompt on the terminal to select the specific version. Once you enter the selection, you get a message which confirms that the selection is updated. ... Run the following commands to install OpenJDK 11 package on Ubuntu 22.04 LTS. ... java -version openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
🌐
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 - Learn how to install and switch Java versions on Ubuntu, using Ubuntu repo or Oracle package. Essential for managing Java on Ubuntu systems.