sudo update-alternatives --config java

Configures the default for the program "java". That's the Java VM.

sudo update-alternatives --config javac

Configures the default Java compiler.

You can also see that, because the first command lists a lot of "JRE" (Java Runtime Environment) folders and the Program is just called "java".

If I check which version is being used by issuing the command java -version or javac -version, I can see, that each command changes the program being used.

However, using update-java-alternatives with a JDK Version changes both programs for me. Using the first commands, you can use a Java VM and Java Compiler from different JDKs.

update-java-alternatives requires presence of a file with extension .jinfo in directory /usr/lib/jvm. The openjdk package is shipped with a .jinfo file, the jdk of Oracle (formerly Sun) is not. As alternative, you configure alternatives without update-java-alternatives:

For example, to add java from jvm-directory /usr/lib/jvm/jdk-12.0.1 (default directory of Debian package of Oracle) with priority 2082, use the following command:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-12.0.1/bin/java 2082

As for switching for different development environments:

Are you talking about starting the IDE itself with different Java versions or using different versions in the IDE for compilation and running your app?

  • For 1.: You can specify which JVM to use in the eclipse.ini, as described here. I don't know how to do that for the Arduino IDE.

  • For 2.: In Eclipse you can select the JRE/JDK to be used in Window -> Preferences -> Java -> Installed JREs. And under Java -> Compiler you could choose an older Java compliance if you wish.

EDIT: This DigitalOcean page also has a very nice explanation of everything related to Java on Ubuntu.

Answer from Benjamin Maurer on askubuntu.com
Top answer
1 of 4
213
sudo update-alternatives --config java

Configures the default for the program "java". That's the Java VM.

sudo update-alternatives --config javac

Configures the default Java compiler.

You can also see that, because the first command lists a lot of "JRE" (Java Runtime Environment) folders and the Program is just called "java".

If I check which version is being used by issuing the command java -version or javac -version, I can see, that each command changes the program being used.

However, using update-java-alternatives with a JDK Version changes both programs for me. Using the first commands, you can use a Java VM and Java Compiler from different JDKs.

update-java-alternatives requires presence of a file with extension .jinfo in directory /usr/lib/jvm. The openjdk package is shipped with a .jinfo file, the jdk of Oracle (formerly Sun) is not. As alternative, you configure alternatives without update-java-alternatives:

For example, to add java from jvm-directory /usr/lib/jvm/jdk-12.0.1 (default directory of Debian package of Oracle) with priority 2082, use the following command:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-12.0.1/bin/java 2082

As for switching for different development environments:

Are you talking about starting the IDE itself with different Java versions or using different versions in the IDE for compilation and running your app?

  • For 1.: You can specify which JVM to use in the eclipse.ini, as described here. I don't know how to do that for the Arduino IDE.

  • For 2.: In Eclipse you can select the JRE/JDK to be used in Window -> Preferences -> Java -> Installed JREs. And under Java -> Compiler you could choose an older Java compliance if you wish.

EDIT: This DigitalOcean page also has a very nice explanation of everything related to Java on Ubuntu.

2 of 4
36

update-java-alternatives is a program to update alternatives for jre/jdk installations.

update-alternatives is a symbolic link management system for linux (I'm sure there is little news here).

You can, and really should, use both update-java-alternatives and update-alternatives together.

Firstly, be sure to have the all the alternatives configured correctly. java and javac are but a few. There is javadoc, rmic, serialver and others, substituting the above variables for: native2ascii and /opt/jdk1.8.0_40/bin/native2ascii should report if the alternative is installed and/or selected.

When all the alternatives are configured you can then create links in /usr/lib/jvm to your manual instalation.

In order to configure update-java-alternatives you must use a hidden file with the same name as your directory but prefixed by a . (dot).

Hope this helps.

Bibliography

man -S 8 update-java-alternatives

http://tech.lanesnotes.com/2008/03/using-alternatives-in-linux-to-use.html

https://stackoverflow.com/questions/6477415/how-to-set-oracles-java-as-the-default-java-in-ubuntu

Top answer
1 of 12
84

Assuming one has installed a JDK in /opt/java/jdk1.8.0_144 then:

  1. Install the alternative for javac

    $ sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.8.0_144/bin/javac 1
    
  2. Check / update the alternatives config:

    $ sudo update-alternatives --config javac
    

If there is only a single alternative for javac you will get a message saying so, otherwise select the option for the new JDK.

To check everything is setup correctly then:

$ which javac
/usr/bin/javac

$ ls -l /usr/bin/javac
lrwxrwxrwx 1 root root 23 Sep  4 17:10 /usr/bin/javac -> /etc/alternatives/javac

$ ls -l /etc/alternatives/javac
lrwxrwxrwx 1 root root 32 Sep  4 17:10 /etc/alternatives/javac -> /opt/java/jdk1.8.0_144/bin/javac

And finally

$ javac -version
javac 1.8.0_144

Repeat for java, keytool, jar, etc as needed.

2 of 12
76

You will notice a big change when selecting options if you type in "java -version" after doing so. So if you run update-alternatives --config java and select option 3, you will be using the Sun implementation.
Also, with regards to auto vs manual mode, making a selection should take it out of auto mode per this page stating:

When using the --config option, alternatives will list all of the choices for the link group of which given name is the master link. You will then be prompted for which of the choices to use for the link group. Once you make a change, the link group will no longer be in auto mode. You will need to use the --auto option in order to return to the automatic state.

And I believe auto mode is set when you install the first/only JRE/JDK.

Discussions

linux - Can I use alternatives to manage multiple installs of Java on Ubuntu 20.04? - Unix & Linux Stack Exchange
TLDR On some Linux systems (RedHat/CentOS based), I have found the UNIX alternatives program being used to manage different versions of java. One of my systems is Ubuntu 20.04, and the alternatives More on unix.stackexchange.com
🌐 unix.stackexchange.com
April 5, 2021
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
xbps-alternatives java
JAVA_HOME won't prevent the installation of a dependency, but you can ignore the package then remove it More on reddit.com
🌐 r/voidlinux
15
5
March 19, 2024
Update-alternatives - Java
Actually by using sudo alternatives --config java you can switch through different providers, qnd all the links will be managed automatically. More on reddit.com
🌐 r/Fedora
2
4
April 21, 2019
🌐
Linux find Examples
queirozf.com › entries › update-alternatives-changing-java-version-on-ubuntu
Update Alternatives: Changing Java version on Ubuntu
May 2, 2022 - $ sudo update-alternatives --list java /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
🌐
Ming's Blog
bitmingw.com › 2019 › 08 › 28 › ubuntu-update-alternatives
Changing the Default Program with update alternatives | Ming's Blog
January 1, 2026 - Each entry here is a shortcut points to the actual program, which may have more than one option (i.e. alternatives). To list all entries of alternatives in the system, use update-alternatives --get-selections. You can see java is pointing to actual program at /usr/lib/jvm/java-11-openjdk-a...
🌐
Ubuntu
manpages.ubuntu.com › trusty › man(8)
Ubuntu Manpage: update-java-alternatives - update alternatives for jre/sdk installations
List all installed packages (or just <jname>) providing information to set a bunch of java alternatives. Verbose output shows each alternative provided by the packages. ... Switch all alternatives of registered jre/sdk installations to automatic mode. ... Set all alternatives of the registered ...
🌐
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 - # List all registered java alternatives update-alternatives --list java # Example output: # /usr/lib/jvm/java-11-openjdk-amd64/bin/java # /usr/lib/jvm/java-17-openjdk-amd64/bin/java # /usr/lib/jvm/java-21-openjdk-amd64/bin/java
🌐
DEV Community
dev.to › thegroo › install-and-manage-multiple-java-versions-on-linux-using-alternatives-5e93
Install and manage multiple Java versions on Linux using alternatives - DEV Community
February 10, 2022 - I will guide you to the process of installing Java 11 and running your first Hello World application using it. The full installation process will be using the command line. So let's start, open a terminal console and cd to your preferred working directory. Make sure to have wget installed. ... Extract it to /usr/lib/jvm/open-jdk-11 folder you have just created. tar -xzf ./openjdk-11+28_linux-x64_bin.tar.gz -C /usr/lib/jvm/open-jdk-11 --strip-components=1 · Update alternatives to add java, javac, jshell and jar
Find elsewhere
🌐
Super User
superuser.com › questions › 1576013 › how-to-use-sudo-update-alternative-for-java-installation-on-ubuntu-18-04
How to use sudo update-alternative for java installation on Ubuntu 18.04? - Super User
August 7, 2020 - I am trying to install Oracle JDK on ubuntu 18.04. I am using the command sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-14.0.2/bin/java 1 but this command does nothing. But...
🌐
GitLab
0xdf.gitlab.io › 2020 › 03 › 24 › update-alternatives.html
update-alternatives | 0xdf hacks stuff - GitLab
March 24, 2020 - I can see the link in /etc has updated: root@kali# tracelnk /bin/nc f: /bin/nc l bin -> usr/bin l nc -> /etc/alternatives/nc l nc -> /bin/nc.traditional l bin -> usr/bin · I’ll run it again and select option 0 to go back to auto for nc. The challenge that got me on this path involved a Java Jar file that was created with Java 8.
🌐
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 - You can actually simplify the process a bit by using the specialized command update-java-alternatives: Quite handy! You can also go back to the latest Java version with a shorthand: -a stands for --auto, meaning the Java version with highest priority (in our case Java 11 with priority 1111). That’s all I have for you today. Short and sweet! Or at least look up the information faster. ↩︎ · Java Ubuntu Linux Tutorials ·
🌐
Django CAS
djangocas.dev › blog › linux › switch-java-version-with-update-alternatives
Switch Java Version with update-alternatives - django-cas-ng
July 7, 2024 - If you want to configure non-interactively you can use the --set option instead. For example, in script you donot want user input. You can use update-alternatives --set java <path> to update java version directly.
🌐
Medium
medium.com › @ayeshajayasankha › how-to-install-and-switch-between-alternative-java-versions-66b3671fc382
How To Install And Switch Between Alternative Java Versions | by Ayesha Jayasankha | Medium
July 3, 2019 - sudo update-alternatives — set java <Directory where JAVA has been extracted>/bin/javasudo update-alternatives — set javac <Directory where JAVA has been extracted>/bin/ javacsudo update-alternatives — set javaws <Directory where JAVA ...
🌐
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.
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - $ 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: $ sudo update-java-alternatives --set java-1.17.0-openjdk-amd64
🌐
SUSE
documentation.suse.com › fr-fr › sles › 15-SP6 › html › SLES-all › cha-update-alternative.html
update-alternatives: managing multiple versions of commands and files | Administration Guide | SLES 15 SP6
March 30, 2026 - Example 22.1: Alternatives System of the java command # /usr/bin/java 1 -> /etc/alternatives/java 2 -> /usr/lib64/jvm/jre-10-openjdk/bin/java 3 · By default, the update-alternatives script is called from inside an RPM package. When a package is installed or removed, the script takes care of all its symbolic links.
🌐
Hostman
hostman.com › tutorials › switching-between-java-versions-on-ubuntu
Switching between Java Versions on Ubuntu Linux
To switch between Java versions and set a default version on Ubuntu Linux, you can use the update-java-alternatives command.
🌐
TecAdmin
tecadmin.net › linux-update-alternatives-command
Update-alternatives Command: A Comprehensive Guide for Linux Users – TecAdmin
April 26, 2025 - sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1100 sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-8-openjdk-amd64/bin/java 800 ... sudo update-alternatives --install /usr/bin/editor editor /usr/bin/vim.basic 100 sudo ...
🌐
Baeldung
baeldung.com › home › installation › removing old versions of java and installing new versions on linux
Removing Old Versions of Java and Installing New Versions on Linux | Baeldung on Linux
January 14, 2025 - $ tar -xvf jdk-21_linux-x64_bin.tar.gz $ sudo mv jdk-21* /opt/ Next, let’s configure the system to recognize this new Java installation: $ sudo update-alternatives --install /usr/bin/java java /opt/jdk-21*/bin/java 1 $ sudo 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 - 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 ...