For Oracle Java 6u30, once you've installed their RPMs you can configure alternatives:

Copy/usr/sbin/alternatives --install "/usr/bin/java" "java" "/usr/java/default/bin/java" 2 \
--slave /usr/bin/javac javac /usr/java/default/bin/javac \
--slave /usr/bin/javadoc javadoc /usr/java/default/bin/javadoc \
--slave /usr/bin/jar jar /usr/java/default/bin/jar \
--slave /usr/bin/keytool keytool /usr/java/default/bin/keytool \
--slave /usr/bin/orbd orbd /usr/java/default/bin/orbd \
--slave /usr/bin/pack200 pack200 /usr/java/default/bin/pack200 \
--slave /usr/bin/rmid rmid /usr/java/default/bin/rmid \
--slave /usr/bin/rmiregistry rmiregistry /usr/java/default/bin/rmiregistry \
--slave /usr/bin/servertool servertool /usr/java/default/bin/servertool \
--slave /usr/bin/tnameserv tnameserv /usr/java/default/bin/tnameserv \
--slave /usr/bin/unpack200 unpack200 /usr/java/default/bin/unpack200 \
--slave /usr/share/man/man1/java.1.gz java.1.gz /usr/java/default/man/man1/java.1.gz \
--slave /usr/share/man/man1/keytool.1.gz keytool.1.gz /usr/java/default/man/man1/keytool.1.gz \
--slave /usr/share/man/man1/orbd.1.gz orbd.1.gz /usr/java/default/man/man1/orbd.1.gz \
--slave /usr/share/man/man1/pack200.1.gz pack200.1.gz /usr/java/default/man/man1/pack200.1.gz \
--slave /usr/share/man/man1/rmid.1.gz rmid.1.gz /usr/java/default/man/man1/rmid.1.gz \
--slave /usr/share/man/man1/rmiregistry.1.gz rmiregistry.1.gz /usr/java/default/man/man1/rmiregistry.1.gz \
--slave /usr/share/man/man1/servertool.1.gz servertool.1.gz /usr/java/default/man/man1/servertool.1.gz \
--slave /usr/share/man/man1/tnameserv.1.gz tnameserv.1.gz /usr/java/default/man/man1/tnameserv.1.gz \
--slave /usr/share/man/man1/unpack200.1.gz unpack200.1.gz /usr/java/default/man/man1/unpack200.1.gz

Then activate the configuration:

Copy/usr/sbin/alternatives --config java

And select /usr/java/default/bin/java from the menu.

Plus you must gzip the man pages

Copygzip /usr/java/default/man/man1/*.1

Also, the Oracle java RPMs might have clobbered your alternatives symlink so force it to be normal.

Copyln -sf /etc/alternatives/java /usr/bin/java
Answer from user783522 on Stack Overflow
🌐
Medium
irsyadsec.medium.com › java-not-found-in-update-alternatives-config-java-after-installing-java-on-linux-d88e499e5c4f
Java not found in “update-alternatives — config java” after installing java on linux | by Irsyad Muhammad Fawwaz | Medium
May 4, 2023 - This is because the system may not have registered Java 18 as an alternative. To fix this, we need to find the path of Java 18 · Enter the following command in your terminal to find the path of Java 18:
Top answer
1 of 6
32

For Oracle Java 6u30, once you've installed their RPMs you can configure alternatives:

Copy/usr/sbin/alternatives --install "/usr/bin/java" "java" "/usr/java/default/bin/java" 2 \
--slave /usr/bin/javac javac /usr/java/default/bin/javac \
--slave /usr/bin/javadoc javadoc /usr/java/default/bin/javadoc \
--slave /usr/bin/jar jar /usr/java/default/bin/jar \
--slave /usr/bin/keytool keytool /usr/java/default/bin/keytool \
--slave /usr/bin/orbd orbd /usr/java/default/bin/orbd \
--slave /usr/bin/pack200 pack200 /usr/java/default/bin/pack200 \
--slave /usr/bin/rmid rmid /usr/java/default/bin/rmid \
--slave /usr/bin/rmiregistry rmiregistry /usr/java/default/bin/rmiregistry \
--slave /usr/bin/servertool servertool /usr/java/default/bin/servertool \
--slave /usr/bin/tnameserv tnameserv /usr/java/default/bin/tnameserv \
--slave /usr/bin/unpack200 unpack200 /usr/java/default/bin/unpack200 \
--slave /usr/share/man/man1/java.1.gz java.1.gz /usr/java/default/man/man1/java.1.gz \
--slave /usr/share/man/man1/keytool.1.gz keytool.1.gz /usr/java/default/man/man1/keytool.1.gz \
--slave /usr/share/man/man1/orbd.1.gz orbd.1.gz /usr/java/default/man/man1/orbd.1.gz \
--slave /usr/share/man/man1/pack200.1.gz pack200.1.gz /usr/java/default/man/man1/pack200.1.gz \
--slave /usr/share/man/man1/rmid.1.gz rmid.1.gz /usr/java/default/man/man1/rmid.1.gz \
--slave /usr/share/man/man1/rmiregistry.1.gz rmiregistry.1.gz /usr/java/default/man/man1/rmiregistry.1.gz \
--slave /usr/share/man/man1/servertool.1.gz servertool.1.gz /usr/java/default/man/man1/servertool.1.gz \
--slave /usr/share/man/man1/tnameserv.1.gz tnameserv.1.gz /usr/java/default/man/man1/tnameserv.1.gz \
--slave /usr/share/man/man1/unpack200.1.gz unpack200.1.gz /usr/java/default/man/man1/unpack200.1.gz

Then activate the configuration:

Copy/usr/sbin/alternatives --config java

And select /usr/java/default/bin/java from the menu.

Plus you must gzip the man pages

Copygzip /usr/java/default/man/man1/*.1

Also, the Oracle java RPMs might have clobbered your alternatives symlink so force it to be normal.

Copyln -sf /etc/alternatives/java /usr/bin/java
2 of 6
9

I can change the default Java on CentOS using these steps:

  1. Add the IBM JDK:

    Copyalternatives --install /usr/bin/java java /opt/WebSphere/AppServer/java/bin/java 3
    
  2. Set the new IBM JDK as default:

    Copyalternatives --config java   (then select #3 in the list)
    
  3. Type java -version at the prompt to see the result.

Discussions

java - sudo: update-alternatives: command not found - Stack Overflow
I am trying to install Java version 8 on my MacOS. The installation guideline advises typing this command: sudo update-alternatives --install /usr/bin/java java /usr/lib/java/JDk.../bin/java But it More on stackoverflow.com
🌐 stackoverflow.com
March 26, 2020
debian - How to use the command update-alternatives --config java - Stack Overflow
SDKMAN! steps in with its easy-to-use Command Line Interface (CLI) and API.” ... You can obtain a JDK from any of these vendors: Amazon, BellSoft, IBM, Red Hat, SAP, Adoptium of the Eclipse Foundation, Oracle, Azul Systems, Microsoft, and more. ... If there is only a single alternative for javac ... More on stackoverflow.com
🌐 stackoverflow.com
Command update-alternatives --config java change nothing - Stack Overflow
I want to switch my java version with the command update-alternatives --config java, but I don't see any changes after that. I'm using that command and have this output: $ sudo update-alternatives -- More on stackoverflow.com
🌐 stackoverflow.com
How to update-java-alternatives successfully to Oracle's one in Debian? - Unix & Linux Stack Exchange
The command update-java-alternatives -s jre-8-oracle-x64 is completely valid (found in documentation also here) but I get errors. The package is also seen in the list of Java packages root@masi:/... More on unix.stackexchange.com
🌐 unix.stackexchange.com
September 19, 2016
🌐
Rocky Linux Forum
forums.rockylinux.org › rocky linux help & support
Alternatives command not working while installing Java - Rocky Linux Help & Support - Rocky Linux Forum
September 14, 2021 - Hi! I currently have a problem with java and creating a link to it in my server. The command alternatives is not doing what I want it to do. At the moment I have this: but my java should link to /usr/lib/jvm/java-1.8.0/bin/java and everytime I try to mess with it I get this error: /usr/lib/jvm/java-1.8.0/bin/java exists and it is not a symlink.
🌐
Stack Overflow
stackoverflow.com › questions › 60863458 › sudo-update-alternatives-command-not-found
java - sudo: update-alternatives: command not found - Stack Overflow
March 26, 2020 - I am trying to install Java version 8 on my MacOS. The installation guideline advises typing this command: sudo update-alternatives --install /usr/bin/java java /usr/lib/java/JDk.../bin/java ... IIRC, update-alternatives is not a MacOS command, but a Linux command.
🌐
TecAdmin
tecadmin.net › linux-update-alternatives-command
Update-alternatives Command: A Comprehensive Guide for Linux Users – TecAdmin
April 26, 2025 - sudo update-alternatives --install ... you encounter an error stating that there are no alternatives for a command, it’s likely that the alternative has not been installed yet....
🌐
Loginroot
pkgs.loginroot.com › errors › notFound › update-java-alternatives
update-java-alternatives: command not found
[root@server ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin If it's empty, You may set the PATH variable with this command · export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" /usr/sbin/update-java-alternatives - from package: java-common You may install the required package with command apt-get install {package}
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.

Find elsewhere
🌐
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.
🌐
LinuxQuestions.org
linuxquestions.org › questions › mandriva-30 › alternatives-command-not-working-384654
alternatives command not working
November 19, 2005 - I am installing Java and following these instructions. When I use the alternatives command I get this response. [timb@Home timb] su - [root@Home root]
🌐
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).
🌐
Stack Overflow
stackoverflow.com › questions › 25692159 › usr-bin-alternatives-command-throws-usage-error
java - /usr/bin/alternatives command throws usage error - Stack Overflow
1 root root 22 Jun 12 10:37 /usr/bin/java -> /etc/alternatives/java MY-MACHINE:/usr/java/jdk1.7.0_55/bin # ls -al /usr/java/jdk1.7.0_55/bin/java -rwxr-xr-x 1 root root 7718 Mar 17 22:05 /usr/java/jdk1.7.0_55/bin/java · Can anyone else see what I'm doing wrong? Cheers. ... That should be --install with two hyphens, not –install with an em-dash or -install with one hyphen.
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
typing: sudo update-alternatives --config java gives an erorr - Linux Mint Forums
November 5, 2017 - sudo apt-get install oracle-java9-installer [/color] VIP: Switching between Oracle Java 8 and Java 9 Later on, if you want to switch Oracle Java 9, use the following command (make sure "oracle-java9-installer" package is installed): ... sudo update-java-alternatives -s java-8-oracle [/color] If you get some warnings when running these two commands, ignore them.
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

🌐
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...