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

🌐
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:
Discussions

Configure alternatives for java 11
I want to be able to ‘script’ the setting of java 11 as the system java, but have not been able to do so reliably, across multiple hosts. Issuing the command “alternatives --config java” displays java-11 and java-1.8.0, not always in the same order, so I cannot reliably set java-11 ... More on forums.rockylinux.org
🌐 forums.rockylinux.org
3
0
May 28, 2025
bash - setting JAVA_HOME and PATH with update-alternatives - Unix & Linux Stack Exchange
EDITED The question was more about bash script them java environment and thanks for those whom had the patience and spare the time to reply me. I am much obliged. As for the Java environment I star... More on unix.stackexchange.com
🌐 unix.stackexchange.com
May 2, 2020
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 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
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.

🌐
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 - sudo update-alternatives --install /usr/bin/jshell jshell /usr/lib/jvm/azul-open-jdk-17/bin/jshell 2 · Now that you have the new JDK installed and configured you can easily switch between versions using: ... Pick the number of the version you want from the Selection list. Type in the Reference number for the one you want to be used from the displayed list and check with java -version the same can be done for, javac, jshell, jar or any other tools you want to manage multiple versions using alternatives on linux.
🌐
Red Hat
access.redhat.com › solutions › 6232511
How to set default Java version with alternatives tool in RHEL on a per user basis - Red Hat Customer Portal
5 days ago - Selection Command ------------... /var/lib/alternatives/java.new: Permission denied Using the alternatives tool allows you to set the system default version as root but does not currently provide options to set different defaults for ...
🌐
Rocky Linux Forum
forums.rockylinux.org › rocky linux help & support
Configure alternatives for java 11 - Rocky Linux Help & Support - Rocky Linux Forum
May 28, 2025 - I want to be able to ‘script’ the setting of java 11 as the system java, but have not been able to do so reliably, across multiple hosts. Issuing the command “alternatives --config java” displays java-11 and java-1.8.0,…
Find elsewhere
🌐
Medium
medium.com › @petehouston › switch-java-versions-on-any-systems-you-like-f0c996b4f57a
Switch Java versions on any systems you like | by Pete Houston | Medium
October 8, 2016 - /usr/libexec/java_home -v MAJOR.MINOR.MACRO_UPDATE · Use the alternative configuration tool, sudo update-alternatives — config java · Use the alternative configuration tool, but first, you must become a superuser · su/usr/sbin/alternatives ...
🌐
Igalia
blogs.igalia.com › dpino › 2011 › 10 › 13 › configuring-different-jdks-with-alternatives
Configuring different JDKs with alternatives - Unweaving the Web
What the hell means each parameter? This is pretty obscure if you don’t really understand what’s the purpose of the ‘*alternatives*‘ program. ... * as *‘java’*, then when later we do: ‘*alternatives –config java*‘, the alternatives for ‘*java*‘ will be listed.
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - We can enlist the available Java versions using the –config option: $ update-alternatives --config java There are 3 choices for the alternative java (providing /usr/bin/java).
🌐
Beyondjava
beyondjava.net › selecting-java-version-macos-linux-windows
Beyond Java
Beyond Java · Sitemap · Talks & Articles · Projects · Guest Posts · About · Legalese · Statistics · (opt out) · Mastodon
🌐
Ubuntu
manpages.ubuntu.com › focal › man(8)
Ubuntu Manpage: update-java-alternatives - update alternatives for jre/sdk installations
update-java-alternatives updates all alternatives belonging to one runtime or development kit for the Java language.
🌐
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 - For example, by default, the command ... To change the default java command to refer to a previous version, run: > sudo update-alternatives --config java root's password: There are 2 choices for the alternative java (providing ...
🌐
Debian Manpages
manpages.debian.org › testing › java-common › update-java-alternatives(8)
update-java-alternatives(8) — java-common — Debian testing — Debian Manpages
August 3, 2024 - update-java-alternatives updates all alternatives belonging to one runtime or development kit for the Java language.
🌐
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 - export JAVA_HOME=<Directory where JAVA has been extracted>/jdk1.8.0export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin ... sudo update-alternatives — install “/usr/bin/java” “java” “<Directory where JAVA has been extracted>/bin/java” 1sudo update-alternatives — install “/usr/bin/javac” “javac” “<Directory where JAVA has been extracted>/bin/javac” 1sudo update-alternatives — install “/usr/bin/javaws” “javaws” “<Directory where JAVA has been extracted>/bin/javaws” 1
🌐
SideStore
sidestore.io
SideStore
An alternative app store for seamless sideloading.
🌐
Oracle
java.com › en › download › help › update_runtime_settings.html
Update Java runtime settings on Windows
SYMPTOMS It is possible that even if you have installed the latest version of Java, your browser may not be able to use it because it is not enabled. This could happen when you install other applications that also install Java and the vendors do not want to change your browser settings.
🌐
GitHub
gist.github.com › 3624261
Updating Default Java via Ubuntu Alternatives · GitHub
Updating Default Java via Ubuntu Alternatives. GitHub Gist: instantly share code, notes, and snippets.
🌐
Medium
medium.com › @adilmustafa006_32164 › install-and-manage-multiple-java-versions-on-linux-using-alternatives-585ac71c23d7
Install and manage multiple Java versions on Linux using alternatives | by Adil Mustafa | Medium
May 1, 2024 - sudo update-alternatives --install /usr/bin/jshell jshell /usr/lib/jvm/azul-open-jdk-17/bin/jshell 2 · Now that you have the new JDK installed and configured you can easily switch between versions using: ... Pick the number of the version you want from the Selection list. Type in the Reference number for the one you want to be used from the displayed list and check with java -version the same can be done for, javac, jshell, jar or any other tools you want to manage multiple versions using alternatives on linux.