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: 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 ·
🌐
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
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.

🌐
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.
🌐
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
1 week ago - Selection Command ------------... the alternatives tool allows you to set the system default version as root but does not currently provide options to set different defaults for individual users....
🌐
Justus-Liebig-Universität Gießen
uni-giessen.de › en › faculties › svc › it › it-service-centre › services › softwarelicenses › oracle › oraclejavaalternatives
Alternatives to Oracle Java — IT Service Centre
Some of these distributions are still free of charge and are based on the identical software sources as Java from Oracle. There are differences in the underlying support and maintenance mechanisms, but not in the functionality of Java itself. Some free alternatives to Oracle Java are presented ...
Find elsewhere
🌐
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 - Issuing the command “alternatives ... be first in the list or second in the list, depending on the Rocky Linux hosts I’m on. The command that I’m scripting sudo echo 1 | sudo alternatives --config java This......
🌐
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 tar -xzf ./zulu17.32.13-ca-jdk17.0.2-linux_x64.tar.gz -C /usr/lib/jvm/azul-open-jdk-17 --strip-components=1 ... You will see a list of configured java in alternatives, the new one is not there so we need to register it like we did in the beginning of this article, let’s do it for java and javac, make sure to check the Selection number and add the new one to the next available, hit enter to continue with the current version before progressing, let’s now register the new one we downloaded.
🌐
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 --config java
🌐
Bell Software
bell-sw.com › blog › oracle-java-alternatives-comparison-of-openjdk-distributions
Alternatives to Oracle Java — Overview of OpenJDK Distributions (2026)
April 21, 2026 - The flagship option for container-native workloads is the Liberica Runtime Container on Alpaquita Linux — BellSoft's own musl and glibc based secure container OS, built, maintained, and supported entirely in-house. This small production Java container image can save up to 30% in disk space and RAM usage compared to standard alternatives.
🌐
Jasondl
jasondl.ee › 2013 › oracle-jdk-and-the-linux-alternatives-system
Oracle JDK and the Linux Alternatives System
January 15, 2013 - I’d rather not monkey with changing PATH and all that, so I turned to the Linux alternatives system to handle things. Sadly, it wasn’t quite that easy, as alternatives needs to know about your alternatives, so before I could change things, I had to educate it, which turned out be easier than I feared. With Java 7 Update 11 installed in /opt/java/jdk1.7.0_11 and symlinked from /opt/java/latest, I had to do two things.
🌐
Which JDK
whichjdk.com
Which Version of JDK Should I Use? | whichjdk.com
The ojdkbuild project had the goal of providing Windows x86_64 binaries of OpenJDK that are as close in behaviour to Linux OpenJDK packages as possible, e.g. by using system libraries instead of packaged versions of zlib or OpenSSL. It used the packages included in CentOS. A use case for these builds was to develop Java software on Windows machines and deploy them to Linux servers in production.
🌐
Deno
deno.com
Deno, the next-generation JavaScript runtime
Deno is the open-source JavaScript runtime for the modern web. Docs · GitHub · Release notes · MacOS/Linux(Currently selected) Windows · curl -fsSL https://deno.land/install.sh | sh · Copy command · Built on web standards with zero-config TypeScript, unmatched security, and a complete built-in toolchain.
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - $ java --version openjdk 17.0.9 2023-10-17 OpenJDK Runtime Environment (build 17.0.9+9-Ubuntu-123.04) update-alternatives is a tool that lets us manage symbolic links between different versions of the same program.
🌐
Django CAS
djangocas.dev › blog › linux › switch-java-version-with-update-alternatives
Switch Java Version with update-alternatives
July 7, 2024 - Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-arm64/bin/java 1111 auto mode * 1 /usr/lib/jvm/java-11-openjdk-arm64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-8-openjdk-arm64/jre/bin/java 1081 manual mode Press <enter> to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/lib/jvm/java-8-openjdk-arm64/jre/bin/java to provide /usr/bin/java (java) in manual mode # java -version openjdk version "1.8.0_312" OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~20.04-b07) OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode) When using the --config option, update-alternatives will list all of the choices for the link group of which given name is the master alternative name.
🌐
CentOS
centos.org
The CentOS Project
Continuously delivered distro that tracks just ahead of Red Hat Enterprise Linux (RHEL) · CentOS stability built for massively large-scale deployments