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

🌐
Ubuntu Manpages
manpages.ubuntu.com › jammy › man(8)
Ubuntu Manpage: update-java-alternatives - update alternatives for jre/sdk installations
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 ...
Discussions

debian - How to use the command update-alternatives --config java - Stack Overflow
#!/bin/bash cd /opt/ sudo mkdir ...jdk-8u192-linux-x64.tar.gz sudo ln -s jdk1.8.0_192 current for file in /opt/java/current/bin/* do if [ -x $file ] then filename=`basename $file` sudo update-alternatives --install /usr/bin/$filename $filename $file 20000 sudo update-alternatives --set $filename $file #echo $file $filename fi done ... I'm using Ubuntu 18.04 ... More on stackoverflow.com
🌐 stackoverflow.com
linux - Can I use alternatives to manage multiple installs of Java on Ubuntu 20.04? - Unix & Linux Stack Exchange
TLDR On some Linux systems (RedHat/CentOS based), I have found the UNIX alternatives program being used to manage different versions of java. One of my systems is Ubuntu 20.04, and the alternatives More on unix.stackexchange.com
🌐 unix.stackexchange.com
April 5, 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
xbps-alternatives java
JAVA_HOME won't prevent the installation of a dependency, but you can ignore the package then remove it More on reddit.com
🌐 r/voidlinux
15
5
March 19, 2024
🌐
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 ...
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.

🌐
Linux find Examples
queirozf.com › entries › update-alternatives-changing-java-version-on-ubuntu
Update Alternatives: Changing Java version on Ubuntu
May 2, 2022 - $ sudo update-alternatives --list java /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
🌐
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)
🌐
Hostman
hostman.com › tutorials › switching-between-java-versions-on-ubuntu
Switching between Java Versions on Ubuntu Linux
To switch between Java versions and set a default version on Ubuntu Linux, you can use the update-java-alternatives command.
Find elsewhere
🌐
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 - # Switch to Java 17 without interaction 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 # Verify java -version
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - $ java --version openjdk 21.0.1 2023-10-17 OpenJDK Runtime Environment (build 21.0.1+12-Ubuntu-223.04) Now, if we need to change the Java version, we can use –set we can use –set: $ sudo update-java-alternatives --set java-1.17.0-openjdk-amd64
🌐
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
🌐
Super User
superuser.com › questions › 1576013 › how-to-use-sudo-update-alternative-for-java-installation-on-ubuntu-18-04
How to use sudo update-alternative for java installation on Ubuntu 18.04? - Super User
August 7, 2020 - I am trying to install Oracle JDK on ubuntu 18.04. I am using the command sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-14.0.2/bin/java 1 but this command does nothing. But...
🌐
FOSS Linux
fosslinux.com › home › linux distributions › debian & ubuntu › ubuntu › how to switch java versions in ubuntu
Switching Java Versions in Ubuntu (2026 Guide)
April 24, 2026 - fosslinux@tuts:~$ update-java-alternatives --list java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64 java-1.17.0-openjdk-amd64 1171 /usr/lib/jvm/java-1.11.0-openjdk-amd64 java-1.21.0-openjdk-amd64 1211 /usr/lib/jvm/java-1.21.0-openjdk-amd64 · If a version you need is missing, install it via the standard Ubuntu 2026 repositories:
🌐
Jason's Web Site
megajason.com › 2021 › 06 › 24 › how-to-use-a-different-java-version-on-ubuntu
How to use a different Java version on Ubuntu – Jason's Web Site
June 25, 2021 - If you’re using just the jre ... flag to limit the action to just the jre-related stuff. sudo update-java-alternatives --jre --set /path/to/java/version...
🌐
GitHub
gist.github.com › 3624261
Updating Default Java via Ubuntu Alternatives · GitHub
Updating Default Java via Ubuntu Alternatives · Raw · install-java-alternatives1.sh · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
Reddit
reddit.com › r/linux4noobs › how do i change default java version on linux mint
r/linux4noobs on Reddit: How do i change default java version on Linux Mint
February 27, 2026 -

I downloaded new fabric mod loader in minecraft and it seems to be that i have problem with my Java version, I was using JDK 21 instead of JDK25.

So i updated by downloading open jdk 25 from Oracle.
i installed .deb file

and when i typed " java --version " in terminal it was still showing that i'm using Java 21

then to change version i used command

sudo update-alternatives --config java

and

sudo update-alternatives --config javac

and selected JDK-25

i closed terminal, opened again and did " java --version" and still it's stuck at Java 21.

am I doing something wrong ?

can someone please help me.

Top answer
1 of 5
8
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.
2 of 5
2
There is a tool often found on Debian and Ubuntu specifically for java versions called "update-java-alternatives" part of the "java-common" package. Example usage: update-java-alternatives --list sudo update-java-alternatives --set java-1.25.0-openjdk-amd64 java --version Whichever tool you use, be sure to call it with --set so the links are created. See this tool is rather simple in principle, you have a pool of packages (often just various versions of the same package) categorized by purpose, then you can specify which one to make "visible" on your path by linking. When you type in "java", you don't really end up running the java executable directly, but a link to the appropriate version you deemed default. Another example would be /usr/bin/editor or simply just run "editor" as /usr/bin is on the path. Now, if you don't like the default "editor" you can swap it out with update-alternatives. When you install a package it may install itself as an alternative for a specific usage. You have installed the downloaded deb file, which I assume should've done just that, so when you list the java alternatives jdk 25 should show up. If it doesn't, that's a different matter, but you can add it manually with the --install flag. https://www.man7.org/linux/man-pages/man1/update-alternatives.1.html Option 2. If you - for whatever reason - don't see value in the above, obviously you can just patch your ~/.bashrc (and .profile for login shells) to add the location to the Java version you want to make "default", for example: export PATH=$PATH:/usr/lib/jvm/java-21-openjdk-amd64/bin But again... alternatives is already nice and useful.
🌐
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 - sudo update-alternatives — set java <Directory where JAVA has been extracted>/bin/javasudo update-alternatives — set javac <Directory where JAVA has been extracted>/bin/ javacsudo update-alternatives — set javaws <Directory where JAVA ...
🌐
LinuxConfig
linuxconfig.org › home › how to install and switch java versions on ubuntu linux
How to Install and Switch Java Versions on Ubuntu Linux
September 21, 2025 - Use the ‘update-alternatives –config javac’ command to select the default Java compiler from the installed versions. ... The headless version is useful for server environments where GUI functionality is not needed, reducing the resource ...
🌐
GitHub
gist.github.com › jeffcogswell › 8c47fb21355faf346a7336998ce76e07
Update Alternatives for Java · GitHub
Some good info here: ... ~/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 ...