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.

Answer from Richard Grimshaw 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 command will show you a list of installed Java versions on your system. Look for the folder with the name “java-18-openjdk-amd64” or something similar to that. Once you find it, copy the full path of that folder. ... Now that we have the path of Java 18, we need to register it as an alternative using the update-alternatives command.
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

Command update-alternatives --config java change nothing - Stack Overflow
If your computer use a java command in a different directory, the update-alternatives will not work. More on stackoverflow.com
🌐 stackoverflow.com
rhel5 - Problem changing Java version using alternatives - Stack Overflow
UPDATE (4/26/10): I followed Bert's suggestion and removed JAVA_HOME from the PATH environment var in /etc/profile. After doing this, I was able to use alternatives to change the version of Java. The only problem is that when I try to run javac, I get "-bash: javac: command not found". More on stackoverflow.com
🌐 stackoverflow.com
java - Error thrown in update-alternatives - Stack Overflow
$ wget http://download.oracle.... 1 $ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jre1.6.0_34/bin/javaws" 1 ... Sign up to request clarification or add additional context in comments. ... While trying cmd1 'sudo add-apt-repository ppa:webupd8team/java' i get below error "sudo: add-apt-repository: command not found" - While trying ... More on stackoverflow.com
🌐 stackoverflow.com
java - OpenJDK and update-alternatives command - Stack Overflow
What is the full list of update-alternatives commands that will change every single Java-related command to a specified Java version? ... While this can be a problem for many software, this is a specific problem for Java on Ubuntu. Fortunately there is a specific solution, a program, call: ... It have change the alternatives of most of the Java related tools. More comment on this subject can be found ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 - If you see the same path (in our example, it is /usr/bin/java), there are no alternatives available for this command. To see the full alternatives (including slaves), use the --display option: > sudo update-alternatives --display java java - ...
🌐
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 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.

🌐
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.
Find elsewhere
🌐
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....
🌐
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 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.
🌐
Command Not Found
command-not-found.com › update-alternatives
command-not-found.com – update-alternatives
Add a symbolic link: sudo update-alternatives --install path/to/symlink command_name path/to/command_binary priority · Configure a symbolic link for `java`: sudo update-alternatives --config java
🌐
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