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.

Answer from Richard Grimshaw on Stack Overflow
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
So, imagine I’m doing a fresh installation, downloaded the latest version of Oracle JDK 1.6 and would like to add it as an alternative. We should run the following command: $ sudo alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_25/bin/java 1000
Discussions

Configure alternatives for java 11
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...... More on forums.rockylinux.org
🌐 forums.rockylinux.org
3
0
May 28, 2025
Why is alternatives command used when installing Java on a Linux machine - Stack Overflow
The below command is need when installing Java on a Linux machine (saw the command in a tutorial). alternatives --install /usr/bin/java java /usr/java/jre1.7.0_01/bin/java 20000 man alternatives More on stackoverflow.com
🌐 stackoverflow.com
linux - alternatives --config java bash script - Stack Overflow
You can run the alternatives command non-interactively too. Instead of --config, use the --set option to specify the path of the alternative directly. Copysudo alternatives --set java /location/of/jdk1.6/bin/java More on stackoverflow.com
🌐 stackoverflow.com
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 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

🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - Afterwards, we’ll enlist the versions again to verify that the JDK has changed successfully: $ update-alternatives --config java There are 3 choices for the alternative java (providing /usr/bin/java).
🌐
Medium
tonylixu.medium.com › linux-alternatives-command-092ae3a3e1e4
Linux — alternatives Command. What is alternatives Command | by Tony | Medium
January 15, 2024 - The alternatives command in Linux is a system utility to manage the different versions of a command or system feature by setting up symbolic links to them. It allows you to seamlessly switch between different versions of a program or command.
🌐
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 - 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 /usr/bin/java).
🌐
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 - When different Java versions are installed on a RHEL system, using the alternatives tool as a regular user fails to set the default version. # alternatives --config java There is 2 program that provides 'java'. Selection Command -----------...
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......
🌐
CommandLinux
commandlinux.com › home › man page › update-java-alternatives
UPDATE-JAVA-ALTERNATIVES linux command man page
April 14, 2026 - A package does provide these information of it’s alternatives in /usr/lib/jvm/.<jname>.jinfo. ... List all installed packages (or just <jname>) providing information to set a bunch of java alternatives.
🌐
Ming's Blog
bitmingw.com › 2019 › 08 › 28 › ubuntu-update-alternatives
Changing the Default Program with update alternatives | Ming's Blog
January 1, 2026 - To list all alternatives of java, use update-alternatives --list java. To set java to use JDK 8 as the default, you can use an interactive command update-alternatives --config 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 - 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.
🌐
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
... The alternatives command (officially part of the chkconfig package on RHEL/CentOS and update-alternatives on Debian/Ubuntu) is a Linux utility designed to manage symbolic links (symlinks) for applications with multiple installed versions.
🌐
Django CAS
djangocas.dev › blog › linux › switch-java-version-with-update-alternatives
Switch Java Version with update-alternatives - django-cas-ng
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.
🌐
Red Hat
redhat.com › en › blog › alternatives-command
Introduction to the alternatives command in Linux
November 20, 2025 - The alternatives command is most useful when managing "generic" application names. Of course in the UNIX world, "generic" isn't always generic any more than "Kleenex" or "Xerox" is in the real world, so terms like java, (x)emacs(-nox), (n)vi(m), whois, and iptables are often some of the first to have alternatives defined for them.
🌐
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 - JAVA_HOME=<Directory where JAVA ... 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 ...
🌐
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.