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
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
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
๐ŸŒ
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 - Ubuntu makes it straightforward to install multiple versions and switch between them. # Check if Java is installed and which version java -version # Check the compiler version javac -version # Find where Java is installed which java readlink -f $(which java) # Show all installed Java versions update-alternatives --list java
๐ŸŒ
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. Itโ€™s a part of the java-common package: ... $ whereis update-java-alternatives update-java-alternatives: /usr/sbin/update-java-alternatives ...
๐ŸŒ
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
Find elsewhere
๐ŸŒ
Medium
tonylixu.medium.com โ€บ linux-alternatives-command-092ae3a3e1e4
Linux โ€” alternatives Command. What is alternatives Command | by Tony | Medium
January 15, 2024 - Selection Command ------------... number: You can also display the current default version of java with: $ sudo alternatives --display java java - status is manual....
๐ŸŒ
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.
๐ŸŒ
Hostman
hostman.com โ€บ tutorials โ€บ switching-between-java-versions-on-ubuntu
Switching between Java Versions on Ubuntu Linux
Upon completing the installation, use the following command to confirm the correct and successful installation of the Java version: ... To switch between Java versions and set a default version on Ubuntu Linux, you can use the update-java-alternatives command.
๐ŸŒ
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
๐ŸŒ
Ubuntu
manpages.ubuntu.com โ€บ bionic โ€บ 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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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...
๐ŸŒ
Django CAS
djangocas.dev โ€บ blog โ€บ linux โ€บ switch-java-version-with-update-alternatives
Switch Java Version with update-alternatives - django-cas-ng
July 7, 2024 - # update-alternatives --set java /usr/lib/jvm/java-8-openjdk-arm64/jre/bin/java update-alternatives: using /usr/lib/jvm/java-8-openjdk-arm64/jre/bin/java to provide /usr/bin/java (java) in manual mode root@9b816ba2e3cb:/project# 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) Alternative, a dedicate command update-java-alternatives can also be used to switch java version...
๐ŸŒ
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
๐ŸŒ
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 - sudo update-java-alternatives --jre --set /path/to/java/version ยท Verify you are now using the desired java version:
๐ŸŒ
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 - 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. ... Hit Ctrl + D to exit. If you have multiple versions of java installed using this same process above, you can just switch between them using alternatives,
๐ŸŒ
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 ... update-alternatives โ€” set javaws <Directory where JAVA has been extracted>/bin/javaws ... Now lets install another version of java to Ubuntu machine.