The command you are looking for is update-alternatives. So you should be running sudo update-alternatives --config java.

Answer from jokerdino on askubuntu.com
🌐
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]
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
update-alternatives broken and php no longer found in cmd - Stack Overflow
I was recommended to run ... did not work for me. What worked however was this: I manually deleted the faulty symlink under /etc/alternatives/php · I ran sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.0 1 which, in contrast to the other commands, created a ... More on stackoverflow.com
🌐 stackoverflow.com
java - OpenJDK and update-alternatives command - Stack Overflow
What is the full list of ... 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 on askubuntu ... More on stackoverflow.com
🌐 stackoverflow.com
linux - Change from update-alternatives command not taking effect - Unix & Linux Stack Exchange
I tried to change my PHP CLI version with sudo update-alternatives --config php: There are 2 choices for the alternative php (providing /usr/bin/php). Selection Path Priority More on unix.stackexchange.com
🌐 unix.stackexchange.com
June 8, 2022
🌐
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
🌐
Stack Overflow
stackoverflow.com › questions › 60863458 › sudo-update-alternatives-command-not-found
java - sudo: update-alternatives: command not found - Stack Overflow
March 26, 2020 - 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.
🌐
CodingTechRoom
codingtechroom.com › question › -fix-sudo-update-alternatives-command-not-found-error
How to Fix 'sudo: update-alternatives: command not found' Error in Linux - CodingTechRoom
The error message 'sudo: update-alternatives: command not found' typically indicates that the system cannot find the 'update-alternatives' command, which is typically used for managing different versions of applications.
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
SOLVED - linux command "update-alternatives" not available on 19.3 - Linux Mint Forums
December 28, 2019 - $ sudo update-alternatives --list python /usr/bin/python2.7 /usr/bin/python3.6 /usr/local/bin/python3.7 Marked SOLVED (maybe some system update was missing)
🌐
Puppy Linux Discussion Forum
oldforum.puppylinux.com › board index › house training › users ( for the regulars )
update-alternatives command not found - (old)Puppy Linux Discussion Forum
Thanks I am running Lucid Puppy version 5.2.5 result I want to see is: pressing Shift + H print the Arabic lettre: ﻻ pressing Shift +T print the Arabic lettre: ﻹ Lettres in Arabic change shape depending on their position in the word Now, for example,the word الثـﻻثاء Should be writen الثـلاثاء on the first shape is not perfectly tied to the next letter (Arabic is RTL) On Ubuntu, thiis achieve simply by ... update-alternatives --set xinput-all_ALL /etc/X11/xinit/xinput.d/default-xim which in Ubuntu returns ... Using '/etc/X11/xinit/xinput.d/default-xim' to provide 'xinput-all_ALL' Using google, I found this fix for fedora
🌐
TecAdmin
tecadmin.net › linux-update-alternatives-command
Update-alternatives Command: A Comprehensive Guide for Linux Users – TecAdmin
April 26, 2025 - Solution: If you encounter an error stating that there are no alternatives for a command, it’s likely that the alternative has not been installed yet.
Find elsewhere
🌐
Loginroot
pkgs.loginroot.com › errors › notFound › update-alternatives
update-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-alternatives - from package: chkconfig You may install the required package with command yum install {package}
🌐
Red Hat
redhat.com › sysadmin › alternatives-command
Introduction to the alternatives command in Linux
November 20, 2025 - The easy solution to this situation, and many other examples similar to it, is to designate the new nem binary as the preferred alternative to the em binary when the em command is used. Manually creating a symlink might seem tempting, but that's not resistant to updates from a package manager, nor is it centralized.
🌐
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}
🌐
Baeldung
baeldung.com › home › administration › the update-alternatives command in linux
The update-alternatives Command in Linux | Baeldung on Linux
July 24, 2024 - Let’s notice that the priority is higher than the highest to date. So the new editor becomes the automatic mode choice. However, we can’t overwrite the manual selection in this way. With micro selected, let’s try to obtain the editor‘s manual: ... So we need to add a slave link to the micro‘s links group. First, let’s check the editor‘s links: $ sudo update-alternatives --display editor editor - auto mode link best version is /usr/bin/micro link currently points to /usr/bin/micro link editor is /usr/bin/editor slave editor.1.gz is /usr/share/man/man1/editor.1.gz # more output skipped
🌐
FedoraForum.org
forums.fedoraforum.org › showthread.php
'alternatives' command missing
I finally got java working after a day and a half, but i noticed amongst my hundreds of searches that a lot of people were using a command ('alternatives') to get it working. I tried the method, but whenever i use alternatives it says: bash: alternatives: command not found Why is that? How ...
🌐
ListAlternatives
listalternatives.com › alternatives-command-not-found
Alternatives Command Not Found​ and Similar Products and Services List - ListAlternatives.com
If you want to remove the unversioned python command, type: sudo alternatives --auto python Conclusion # ... new appuals.com Whenever there is an error ' command not found ' on your Terminal, it means that the command you are trying to use for specific application or library is not available.
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.

🌐
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…
🌐
Django CAS
djangocas.dev › blog › linux › switch-java-version-with-update-alternatives
Switch Java Version with update-alternatives - django-cas-ng
July 7, 2024 - When run update-alternatives, got command not found error: # update-alternatives bash: update-alternatives: command not found · update-alternatives is available in apt, use apt-get install to install: apt-get install -y update-alternatives · update-alternatives(1) — Linux manual page ·