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.

🌐
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 - # Check if Java is installed and ... list sudo apt update # Install the default JDK (usually the latest LTS available) sudo apt install default-jdk # Install a specific version sudo apt install openjdk-8-jdk # Java 8 sudo apt install openjdk-11-jdk # Java 11 (LTS) sudo apt install openjdk-17-jdk # Java 17 ...
🌐
OneUptime
oneuptime.com › home › blog › how to switch between java versions on ubuntu
How to Switch Between Java Versions on Ubuntu
March 2, 2026 - # Set Java 17 as the default without interactive menu sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac · This is useful in provisioning ...
🌐
Usgs
ghsc.code-pages.usgs.gov › hazdev › pdl › userguide › getting-started › installing-java-walkthrough.html
Installing Java walkthrough
To resolve the issue, install Java 17 using the following command: ... Verify the Java version is now using version 17. If the old version is stil being used, update to the new version by following the prompts of the following command: ... # update-alternatives --config java There are 2 choices ...
🌐
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 ...
Find elsewhere
🌐
Django CAS
djangocas.dev › blog › linux › switch-java-version-with-update-alternatives
Switch Java Version with update-alternatives - django-cas-ng
July 7, 2024 - Example: # apt-cache search openjdk ... Kit (JDK) openjdk-17-jdk - OpenJDK Development Kit (JDK) Then just install by apt-get, Example: apt-get install -y openjdk-17-jdk · When run update-alternatives, got command not found error: # update-alternatives bash: update-alternatives: ...
🌐
LinuxVox
linuxvox.com › blog › why-is-alternatives-command-used-when-installing-java-on-a-linux-machine
Why Use the Alternatives Command When Installing Java on Linux? Explaining the 20000 Value — linuxvox.com
You’ll see entries for both Java 11 and 17, each with their priorities (e.g., 11000 and 17000). If you installed Java manually (e.g., from Oracle’s website), you’ll need to register it with alternatives using --install. For example, to register a manually installed Java 21 at /opt/jdk-21: # Syntax: update-alternatives --install <link> <name> <path> <priority> sudo update-alternatives --install /usr/bin/java java /opt/jdk-21/bin/java 21000 sudo update-alternatives --install /usr/bin/javac javac /opt/jdk-21/bin/javac 21000
🌐
SantaSoft
dario9325.github.io › oracle-jdk17-alternatives
Adding Oracle JDK17 in Debian Alternative system | SantaSoft
stylee@matrix17:~$ sudo update-java-alternatives -l java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64 jdk-11.0.12 1112 /usr/lib/jvm/jdk-11.0.12 jdk-17 1700 /usr/lib/jvm/jdk-17 oracle-java6-jdk-amd64 316 /usr/lib/jvm/oracle-java6-jdk-amd64 oracle-java8-jdk-amd64 318 /usr/lib/jvm/oracle-java8-jdk-amd64 stylee@matrix17:~$ But it’s not finished, yet: we have to tell update-alternatives which binary to bind. ... sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-17/bin/java 1700 sudo update-alternatives --install /usr/bin/jexec jexec /usr/lib/jvm/jdk-17/lib
🌐
SUSE
documentation.suse.com › sles › 15-SP5 › html › SLES-all › cha-update-alternative.html
update-alternatives: managing multiple versions of commands and files | Administration Guide | SLES 15 SP5
April 6, 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 ...
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - $ update-java-alternatives --list java-1.17.0-openjdk-amd64 1711 /usr/lib/jvm/java-1.17.0-openjdk-amd64 java-1.21.0-openjdk-amd64 2111 /usr/lib/jvm/java-1.21.0-openjdk-amd64 java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
🌐
CircleCI
discuss.circleci.com › build environment
Upgrade Java to JDK 17 - Build Environment - CircleCI Discuss
December 15, 2022 - I have an application that needs Java 17 to run successfully, but I am unable to upgrade Java 11 to Java 17 in the config. I have tried other guides, but they have not worked for me. I’m getting this error. > You are using an outdated version of Java (13). Java 17 or higher is required.
🌐
Medium
irsyadsec.medium.com › java-not-found-in-update-alternatives-config-java-after-installing-java-on-linux-d88e499e5c4f
Java not found in “update-alternatives — config java” after installing java on linux | by Irsyad Muhammad Fawwaz | Medium
May 4, 2023 - This command will show you a list of installed Java versions on your system. Look for the folder with the name “java-18-openjdk-amd64” or something similar to that. Once you find it, copy the full path of that folder. ... Now that we have the path of Java 18, we need to register it as an alternative using the update-alternatives command.
🌐
Java With Us
javawithus.com › home › faq › how to install java 17 on windows, mac and linux
How to Install Java 17 on Windows, Mac and Linux | Java With Us
April 21, 2026 - Install both JDKs. On macOS, /usr/libexec/java_home -v 17 or -v 21 points at the right installation. On Linux, sudo update-alternatives --config java lets you pick the default.
🌐
SUSE
documentation.suse.com › sles › 15-SP1 › html › SLES-all › cha-update-alternative.html
SUSE - Open Source Solutions for Enterprise Servers & Cloud
July 18, 2022 - Find the latest updates, including new features, enhancements, bug fixes, and important information about deprecated or removed packages.