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
🌐
Beyondjava
beyondjava.net › selecting-java-version-macos-linux-windows
Selecting a Java Version on MacOS, Linux, and Windows
Beyond Java · Sitemap · Talks & Articles · Projects · Guest Posts · About · Legalese · Statistics · (opt out) · Mastodon
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

Discussions

Replacement for Java?
Amazon Corretto? More on reddit.com
🌐 r/sysadmin
17
9
May 31, 2022
java - Switch JDK version in Windows 10 cmd - Stack Overflow
Is there a way to change JDK version easily in cmd? like the version on mac. Change Default JDK on Mac. More on stackoverflow.com
🌐 stackoverflow.com
I installed the latest version of java, but when I type "java --version" on terminal it shows the old one.
The most likely reason this shows up in your terminal is because your old Java version is in the PATH environment variable. Irrespective of your OS, make sure you add the path to the new java installation to your PATH environment variable, and that this new version comes earlier in your PATH variable than the older java installation. The best practice in adding java path to the environment variable is to make a new environment variable called JAVA_HOME and then using that in the PATH environment variable or any other environment variables where you need java. More on reddit.com
🌐 r/javahelp
10
7
January 14, 2023
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
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.

🌐
Bell Software
bell-sw.com › blog › updating-the-java-version
How to update Java: A comprehensive guide
September 5, 2024 - Note that different JDK vendors ... of the alternatives described below may not be available with your vendor. We use Liberica JDK 21, the latest minor release available at the moment of writing this article, as an example. If you don’t use package managers, there are two convenient ways to update Java on Windows...
🌐
GitHub
gist.github.com › jeffcogswell › 8c47fb21355faf346a7336998ce76e07
Update Alternatives for Java · GitHub
Some good info here: http://askubuntu.com/questions/159575/how-do-i-make-java-default-to-a-manually-installed-jre-jdk · I usually install my JDK under /usr/lib/jvm alongside the others: cd /usr/lib/jvm sudo tar xf ~/Downloads/jdk-8u91-linux-x64.tar.gz sudo chown -R root:root jdk1.8.0_91 sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_91/bin/java 1 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_91/bin/javac 1 sudo update-alternatives --install /usr/bin/jexec jexec /usr/lib/jvm/jdk1.8.0_91/lib/jexec 1 sudo update-alternatives --config java sudo update-alternatives --config javac sudo update-alternatives --config jexec
🌐
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
🌐
GitHub
gist.github.com › bench › 3935f5e72c7dca83a4e31210b2c305e9
java and javac update-alternatives · GitHub
$ sudo update-alternatives --install /usr/bin/javac javac /home/bchenebault/Apps/jdk1.5.0_22/bin/javac 1 $ sudo update-alternatives --install /usr/bin/javac javac /home/bchenebault/Apps/jdk1.6.0_45/bin/javac 2 $ sudo update-alternatives --install /usr/bin/javac javac /home/bchenebault/Apps/jjdk1.7.0_79/bin/javac 3 $ sudo update-alternatives --install /usr/bin/javac javac /home/bchenebault/Apps/jdk1.8.0_101/bin/javac 4
Find elsewhere
🌐
SUSE
documentation.suse.com › 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 ...
🌐
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 ...
🌐
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 ...
🌐
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
There are also other alternatives. In order to be able to use these, a (possibly) existing Oracle Java installation must first be removed from the system. Information on how to do this can be found here. There are also software updates for the Oracle Java alternatives presented below, based ...
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - galternatives is a GUI front-end to update-alternatives. It enables users to choose a particular application to run for common commands. Let’s see how to use galternatives to choose a Java version.
🌐
CommandLinux
commandlinux.com › home › man page › update-java-alternatives
UPDATE-JAVA-ALTERNATIVES linux command man page
April 14, 2026 - 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 jre/sdk installation to the program path provided by the <jname> installation.
🌐
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.
🌐
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.
🌐
HappyCoders.eu
happycoders.eu › java › how-to-switch-multiple-java-versions-windows
How to Change Java Versions in Windows (up to Java 25)
June 11, 2025 - Hi Chris, I have released a new set of scripts that also contain commands to switch the Java version permanently (see section "Temporary, Permanent and System-Wide Java Version Changes"). ... These don't seem to be permanent at all. Is it just for me? (Yes the new scripts system and user scripts) ... UPDATE: I have uploaded a new version of the scripts.
Top answer
1 of 7
16

Here's my guide for Windows 10.

Step 1. Go to System Properties. Click on Environment Variables

Step 2. Add new variables, such as JAVA_8_HOME

  • JAVA_8_HOME:%ProgramFiles%\Java\jdk1.8.0_152\bin
  • JAVA_9_HOME:%ProgramFiles%\Java\jdk-9.0.1\bin
  • JAVA_HOME:%JAVA_8_HOME%

In my case, JAVA_8_HOME(JDK8) is pointing to C:\Program Files\Java\jdk1.8.0_152\bin. You can replace this with your own path to javac. %JAVA_HOME% has a default value pointing to JAVA_8_HOME, which is the path for JDK8. That's my preference, feel free to adjust accordingly.

Step 3. Select PATH and click on Edit. PATH

Step 4. Click on New and add %JAVA_HOME%. %JAVA_HOME% will be added to PATH automatically every time you launch a command prompt.


In order to switch JDK version in cmd, here's the trick. Step 5. I created a batch file with

@echo off
:: Switch JDK version
DOSKEY java8=SET PATH=%JAVA_8_HOME%;%PATH%;
DOSKEY java9=SET PATH=%JAVA_9_HOME%;%PATH%

Basically, it disables echo and creates two alias. In batch file any string after :: is the comments. Every time, java8 or java9 is called, it re-exports %PATH% with the new JDK path. Save it as profile.bat. You can name it whatever you want.

Step 6. Search for regedit (Registry Editor). Click on Edit > New > String Value. Give AutoRun as the Value name and %USERPROFILE%\profile.bat as the Value data. Here, please put your actual path value to the profile.bat we just created. So, whenever a command prompt is opened, it automatically loads profile.bat, which creates those two alias in the script.

Step 7. Close any command prompt you're using or just open a new command prompt. This is because your changes will not affect opened cmd window. Environment changes only happens to new CMD.

Step 8. Verify your results here.

If you're using different Python versions, same trick applies, too. Find my python environment settings here.

2 of 7
5

I created scripts for every version of Java that I have installed on my PC, and use those whenever I need to change the Java version through the command line. Here is an example of one, should be self-explanatory really:

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk-10
echo Setting PATH
set PATH=C:\Program Files\Java\jdk-10\bin;%PATH%
echo Display java version
java -version
🌐
javaspring
javaspring.net › blog › update-alternatives-java
Update Alternatives Java: A Comprehensive Guide — javaspring.net
To list all the available alternatives for the java command, you can use the following command: ... This command will show you the paths to all the available java executables on your system. To switch between different Java versions, you can use the following command: ... When you run this command, you will see a list of available Java versions with a corresponding number. You can then enter the number of the Java version you want to use, and update-alternatives will update the symbolic links accordingly.