It updates the links in /etc/alternatives to point to the program for this purpose. There's lots of examples, like x-www-browser, editor, etc. that will link to the browser or editor of your preference. Some scripts or system tools may want you to edit a file manually (e.g. configuration conflict in dpkg) and they'll look into the alternatives to give you the editor of choice. For java, this is the Java runtime environment - Oracle's, OpenJRE, etc.

The links in /etc/alternatives are just symbolic links. You can see them using for example

ls -l /etc/alternatives

Moreover, the regular /usr/bin binaries are also symlinks. E.g.:

ls -l /usr/bin/java
  lrwxrwxrwx 1 root root 22 Aug 14 10:33 /usr/bin/java -> /etc/alternatives/java
ls -l /etc/alternatives/java
  lrwxrwxrwx 1 root root 46 Aug 14 10:33 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java

So, no PATH has to be modified. It just uses symbolic links.

Answer from gertvdijk on askubuntu.com
🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › update-alternatives.1.html
update-alternatives(1) - Linux manual page
Note: In most (if not all) cases no other maintainer script actions should call update-alternatives, in particular neither of upgrade nor disappear, as any other such action can lose the manual state of an alternative, or make the alternative temporarily flip-flop, or completely switch when ...
🌐
Linux Man Pages
linux.die.net › man › 8 › update-alternatives
update-alternatives(8) - Linux man page
When each package providing a file with a particular functionality is installed, changed or removed, alternatives is called to update information about that file in the alternatives system. alternatives is usually called from the %post or %pre scripts in RPM packages.
Discussions

java - what is update-alternatives command in linux and what is the use of it? - Stack Overflow
I hope to be clear enough, Here there is a post regarding java alternatives. For the complete usage list I suggest to look at the same manual page, typing man update-alternatives on your OS shell; More on stackoverflow.com
🌐 stackoverflow.com
command line - Better way to add alternative using update-alternatives? - Unix & Linux Stack Exchange
I've looked up the manual of update-alternatives several times but I can't find out how to show the current link pointing to a specific alternative, and that information is needed when adding a new alternative. More on unix.stackexchange.com
🌐 unix.stackexchange.com
July 6, 2013
debian - Install man pages in directory with update-alternatives - Unix & Linux Stack Exchange
Using update-alternatives(8) on a Debian system it is possible to add man pages as slaves under some master alternative. For example, the following command installs an alternative man page tclsh.1 More on unix.stackexchange.com
🌐 unix.stackexchange.com
May 11, 2013
Understanding update-alternatives
You're in luck. A year or so ago, I started documenting everything I learn on linux, so I don't have to go through the annoying process of re-learning it. Here are my notes on update-alternatives: install a new default browser in ubuntu: sudo update-alternatives --install /usr/bin/x-www-browser x-www-browser /opt/mozilla/vanilla/firefox/firefox 100 the incantation is: --install So, for your case, you'd want to do this: sudo update-alternatives --install /usr/bin/editor editor /usr/bin/atom 100 For your editor, you'll also want to set the $EDITOR environment variable. You can do this by editing your shell configuration, by entering: atom ~/.bashrc and add this: export EDITOR=/usr/bin/atom You can see why I took notes on update-alternatives. The incantation is kind of weird. More on reddit.com
🌐 r/linux4noobs
9
3
August 2, 2019
🌐
Baeldung
baeldung.com › home › administration › the update-alternatives command in linux
The update-alternatives Command in Linux | Baeldung on Linux
July 24, 2024 - 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
Top answer
1 of 2
9

Basically it says to your machine to use this alternative of Jave JDK instead of the default one, which, in Linux systems, is OpenJDK.

A brief extract from the man page is better than any answer I could write:

update-alternatives creates, removes, maintains and displays information about the symbolic links comprising the Debian alternatives system.

It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time. For example, many systems have several text editors installed at once. This gives choice to the users of a system, allowing each to use a different editor, if desired, but makes it difficult for a program to make a good choice for an editor to invoke if the user has not specified a particular preference.

Debian's alternatives system aims to solve this problem. A generic name in the filesystem is shared by all files providing interchangeable functionality. The alternatives system and the system administrator together determine which actual file is referenced by this generic name. For example, if the text editors ed(1) and nvi(1) are both installed on the system, the alternatives system will cause the generic name /usr/bin/editor to refer to /usr/bin/nvi by default. The system administrator can override this and cause it to refer to /usr/bin/ed instead, and the alternatives system will not alter this setting until explicitly requested to do so.

With --install you specified a link, "/usr/bin/java" a name "java" and a path "/usr/lib/java/JDK...." and you add a group of alternatives to the system. link is the generic name for the master link, name is the name of its symlink in the alternatives directory, and path is the alternative being introduced for the master link.

I hope to be clear enough, Here there is a post regarding java alternatives.

For the complete usage list I suggest to look at the same manual page, typing man update-alternatives on your OS shell;

2 of 2
0

i want to explain it for you from scratch ... if you have 2 or more versions of a program that starts with a same command in linux you can use update-alternatives command for determining the default version of that program and you can also change the default version of that command easily .. assume that you have 2 version of python on your system. python 2 & python 3. by default python command on linux starts the python2 interpreter on the shell . you think that python 2 is old and you want to use python 3 instead of python2 . one of the solution is that you enter python3 command on the shell and start the python interpreter that its version is more than 3 ... but you want to enter python command and shell recognize that you want to run python3 interpreter . here,update-alternatives command do it's work and determine the default version and versions of a program you want to use for a specific command .

i told you that python command start python 2 interpreter by default . you want to change it . follow the example :

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1.

when you execute this command on linux you are telling to shell that after this time two links of two different programs are linked to python command on linux .. infact you install the python3 program on python command on linux and two programs exist at 1 command that you can change the defaults of these programs and run what of these programs you want by changing priority in command or configure it manually to set the default program ..

hope this is useful for you !

🌐
Debian
wiki.debian.org › DebianAlternatives
DebianAlternatives - Debian Wiki
One way to find the syntax is to look at the postinst script of something already providing an alternative. If you have added the new alternative with a higher priority it will be automatically promoted to the default: $ update-alternatives --config www-browser There are 2 choices for the ...
🌐
SUSE
documentation.suse.com › sled › 15-SP7 › html › SLED-all › cha-update-alternative.html
update-alternatives: managing multiple versions of commands and files | Administration Guide | SLED 15 SP7
May 12, 2024 - But you can run it manually from the command line for: displaying the current alternatives for a generic name. ... > sudo update-alternatives --get-selections asadmin auto /usr/bin/asadmin-2.7 awk auto /usr/bin/gawk chardetect auto /usr/bin/chardetect-3.6 dbus-launch auto /usr/bin/dbus-launch.x11 default-displaymanager auto /usr/lib/X11/displaymanagers/gdm [...]
🌐
Ubuntu Manpages
manpages.ubuntu.com › manpages › trusty › en › man8 › update-alternatives.8.html
Ubuntu Manpage: update-alternatives - maintain symbolic links determining default commands
In the process, the master symlink and its slaves are updated to point to the highest priority installed alternatives. --display · name Display information about the link group. Information displayed includes the group's mode (auto or manual), which alternative the master link currently points to, what other alternatives are available (and their corresponding slave alternatives), and the highest priority alternative currently installed.
Find elsewhere
🌐
DEV Community
dev.to › webduvet › how-to-manage-versions-using-update-alternatives-258e
How to manage versions using update-alternatives - DEV Community
November 24, 2022 - It is a tool provided by Debian based distributions which is designed to help to manage multiple versions or different implementations of a command or program, read more on Debian Alternatives. Update-alternatives in Debian based system like Ubuntu is used as default option by apt, however, it offers the command-line interface to interact with the settings and to add and remove entries manually.
🌐
Red Hat
redhat.com › en › blog › alternatives-command
Introduction to the alternatives command in Linux
November 20, 2025 - In theory, a Linux sysadmin can offer many system tools according to function rather than by the exact name of the executable, but that often requires a lot of symlinking and version tracking. Unless that is, you use the alternatives command. The alternatives command began its life as, interestingly, an alternative. Originally, this was a convenience utility, written in Perl, from the Debian Linux project, called update-alternatives.
🌐
LinuxConfig
linuxconfig.org › home › how to set default programs using update-alternatives on debian-based distributions
How to set default programs using update-alternatives on Debian-based distributions
February 1, 2023 - To list all the groups of alternatives available on the system, we just invoke “update-alternatives” with the --get-selections option: ... arptables auto /usr/sbin/arptables-nft awk auto /usr/bin/mawk builtins.7.gz auto /usr/share/man/man7/bash-builtins.7.gz cpp auto /usr/bin/cpp default-GM.sf2 auto /usr/share/sounds/sf2/TimGM6mb.sf2 default-GM.sf3 auto /usr/share/sounds/sf2/TimGM6mb.sf2 desktop-background auto /usr/share/desktop-base/active-theme/wallpaper/contents/images/1920x1080.svg desktop-background.xml auto /usr/share/desktop-base/active-theme/wallpaper/gnome-background.xml desktop-
Top answer
1 of 4
19

To answer your first question I'd like to hint you to --query:

   --query name
          Display information about the link group like --display does, but in a machine parseable way (see section QUERY FORMAT below).

Armed with this you will get the link source, e.g. in my case for java:

usr@srv % update-alternatives --query java
Name: java
Link: /usr/bin/java
[...]

So, you see my chain goes like /usr/bin/java -> /etc/alternatives/java -> ....

Unfortunately, I don't have an answer to your second question. I've been searching for a solution for this some time ago, but it seems that there is no simple workaround, yet. What you could do is writing some hack to parse the output of the --query call, maybe like this:

update-alternatives --query java | /bin/grep Link | cut -f 2 -d " "

which you could then use as input for the --install call. But since this is quite messy in my opinion I won't recommend it. Instead you might want to have a look at galternatives, a front-end to the alternatives system. Even if I don't like to use graphical stuff for such basic jobs it is quite convenient and I ended up using this tool instead of the command line tools.

EDIT

I've been curious how update-alternatives knows what's the command symlink and took a short look into the sources. Of course the alternatives system has to store the config for each group and it turns out that it's called administrative directory and written on the man page ;-)

You'll find this information in /var/lib/dpkg/alternatives (by default). The second line in each of these files defines the master link you're looking for. You may extract it like this:

usr@srv $ sed -ne 2p /var/lib/dpkg/alternatives/java
/usr/bin/java

However, this is just a workaround for those having an older version of update-alternatives.

2 of 4
5

Simpleton question here: Isn't the <link> always going to be the same one retrieved by a simple which [program] since that is the link that the system uses to call a program by command-line?

For instance, tracing back the links for pycharm I get:

user@computer:~$ which pycharm
/usr/bin/pycharm
user@computer:~$ ll /usr/bin/pycharm
lrwxrwxrwx 1 root root 25 Mar 12  2015 /usr/bin/pycharm -> /etc/alternatives/pycharm*
user@computer:~$ ll /etc/alternatives/pycharm 
lrwxrwxrwx 1 root root 43 Mar 12  2015 /etc/alternatives/pycharm -> /opt/pycharm-community-4.0.5/bin/pycharm.sh*

And I can then use:

sudo update-alternatives --install /usr/bin/pycharm pycharm /opt/pycharm-community-4.5.0/bin/pycharm.sh 0

For my new pycharm install.

Then maybe you could construct a script to use the output of which.

🌐
SUSE
documentation.suse.com › es-es › sles › 15-SP1 › html › SLES-all › cha-update-alternative.html
SLES 15 SP1 | Administration Guide | update-alternatives: Managing Multiple Versions of Commands and Files
But you can run it manually from the command line for: displaying the current alternatives for a generic name. ... > sudo update-alternatives --get-selections asadmin auto /usr/bin/asadmin-2.7 awk auto /usr/bin/gawk chardetect auto /usr/bin/chardetect-3.6 dbus-launch auto /usr/bin/dbus-launch.x11 default-displaymanager auto /usr/lib/X11/displaymanagers/gdm [...]
🌐
Stack Exchange
unix.stackexchange.com › questions › 75457 › install-man-pages-in-directory-with-update-alternatives
debian - Install man pages in directory with update-alternatives - Unix & Linux Stack Exchange
May 11, 2013 - For example, the following command installs an alternative man page tclsh.1 alongside the alternative executable for tclsh. $ update-alternatives --install /usr/bin/tclsh tclsh /usr/bin/tclsh8.6.0 100 \ --slave /usr/share/man/man1/tclsh.1 tclsh.1 /usr/share/man/man1/tclsh8.6.0.1
🌐
TecAdmin
tecadmin.net › linux-update-alternatives-command
Update-alternatives Command: A Comprehensive Guide for Linux Users – TecAdmin
April 26, 2025 - For example, you have 2 versions of Java installed on your system. Thyen you can install the alternatives as: sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1100 sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-8-openjdk-amd64/bin/java 800
🌐
Williamdemeo
williamdemeo.github.io › linux › update-alternatives.html
update-alternatives - William DeMeo
March 13, 2014 - # install ruby1.8 & friends with priority 500 # so this will be the default "auto" choice update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.8 500 \ --slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \ /usr/share/man/man1/ruby.1.8.gz \ --slave /usr/bin/ri ri /usr/bin/ri1.8 \ --slave /usr/bin/irb irb /usr/bin/irb1.8 # install ruby1.9 & friends with priority 400 update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9 400 \ --slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \ /usr/share/man/man1/ruby.1.9.gz \ --slave /usr/bin/ri ri /usr/bin/ri1.9 \ --slave /usr/bin/irb irb /usr/bin/irb1.9 # choose your interpreter # changes symlinks for /usr/bin/ruby , # /usr/bin/irb, /usr/bin/ri and man (1) ruby update-alternatives --config ruby
🌐
Reddit
reddit.com › r/linux4noobs › understanding update-alternatives
r/linux4noobs on Reddit: Understanding update-alternatives
August 2, 2019 -

(tl;dr at bottom)

Apologies for sounding dumb, but I'm trying to understand Ubuntu's update-alternatives by reading the man pages and I just can't seem to understand it.

I'm trying to set atom (/usr/bin/atom) as an alternative for editor. There are two ways the man pages seem to be telling me to do it, but I get an error on both that I don't totally understand:

$ sudo update-alternatives --set editor /usr/bin/atom
update-alternatives: error: alternative /usr/bin/atom for editor not registered; not setting

There's also update-alternatives --install <link> <name> <path> <priority>, but I can't figure out what it wants for <link>. For all other alternatives it seems to just be a symlink to <path>, which is a bit strange, but I tried creating a symlink and I got an error Okay, now I'm not getting the same error, but it was something like "Max recursion reached". Now I can set the editor alternative to atom, but nothing appears to be different when I try to open a text document.

I feel like I'm just misunderstanding the arguments... could I get some help, please?

TL;DR I want to set /usr/bin/atom as the editor alternative, how do I do it

🌐
Linux Hint
linuxhint.com › update_alternatives_ubuntu
How to Use update-alternatives Command on Ubuntu – Linux Hint
In auto mode, the alternatives selects the command/executable/alternative with the highest available priority by default. In manual mode, you select the default command/executable/alternative for the alternatives manually.
🌐
SourceForge
alternatives.sourceforge.net
Alternatives system. - SourceForge
You can turn into manual mode any available item. There are only one difference between master and slave: weight calculation algorithm. Slave alternative have same weight as a master alternative. alternatives-update script corrects invalid manual alternatives, by switching them into auto mode.