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.

Discussions

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
Setting JAVA_HOME path
It means that you have not configured the JAVA_HOME environment variable. Using a virtual terminal application, type in: update-alternatives --config java, which will give you the location of JDK listed under Path column. Depending on the installed version of JDK, it will be something like: /usr/lib/jvm/java-14-openjdk-amd64/bin/java If you have installed multiple versions of JDK, all of them will be listed here 2. Using text editor such as nano and terminal emulator, type in: nano /etc/profile.d/jdk_home.sh This will create and open for editing a new script file named jdk_home.sh under the location /etc/profile.d, where you need to type in: export JAVA_HOME= where JDK-Location should not include the /bin/java directories. For example: EXPORT JAVA_HOME=”/usr/lib/jvm/java-14-openjdk-amd64” This will set your environment variable JAVA_HOME The steps above are if you have installed JDK using apt package manager tool, you also have the option of using SDKMAN which will configure all environment variables for you automatically. More on reddit.com
🌐 r/vscode
12
1
February 27, 2020
Any Linux alternatives to Filebot?

It works on most platforms, including Linux. https://github.com/tinyMediaManager/tinyMediaManager

More on reddit.com
🌐 r/DataHoarder
43
16
December 11, 2018
🌐
Ubuntu
manpages.ubuntu.com › focal › man(8)
Ubuntu Manpage: update-java-alternatives - update alternatives for jre/sdk installations
update-java-alternatives updates all alternatives belonging to one runtime or development kit for the Java language.
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - update-java-alternatives is a tool that lets us manage different versions of Java on Debian and 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:
🌐
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 set java to use JDK 8 as the default, you can use an interactive command update-alternatives --config java.
🌐
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
Find elsewhere
🌐
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.
🌐
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 - What is the command to list all installed Java versions on Ubuntu? Use ‘update-java-alternatives -l’ to list all installed Java versions and their paths.
🌐
Django CAS
djangocas.dev › blog › linux › switch-java-version-with-update-alternatives
Switch Java Version with update-alternatives - django-cas-ng
July 7, 2024 - If you want to configure non-interactively you can use the --set option instead. For example, in script you donot want user input. You can use update-alternatives --set java <path> to update java version directly.
🌐
OneUptime
oneuptime.com › home › blog › how to switch between java versions on ubuntu
How to Switch Between Java Versions on Ubuntu
March 2, 2026 - /usr/lib/jvm/java-11-openjdk-amd64/ /usr/lib/jvm/java-17-openjdk-amd64/ /usr/lib/jvm/java-21-openjdk-amd64/ Ubuntu's update-alternatives system manages symbolic links to multiple versions of the same tool.
🌐
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 ...
🌐
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 - sudo update-alternatives --install /usr/bin/jshell jshell /usr/lib/jvm/azul-open-jdk-17/bin/jshell 2 · Now that you have the new JDK installed and configured you can easily switch between versions using: ... Pick the number of the version you ...
🌐
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...
🌐
GitHub
gist.github.com › 3624261
Updating Default Java via Ubuntu Alternatives · GitHub
Updating Default Java via Ubuntu Alternatives. GitHub Gist: instantly share code, notes, and snippets.