What is the command update-alternatives
used for?
Take this example:
sudo update-alternatives --install /usr/bin/java java /usr/local/java/jre1.7.0_09/bin/java 1
What does it do? How is it different from adding jdk to the path?
Let's say that I have run the command. How would I revert back to the original state?
It updates the links in
/etc/alternatives
to point to the program for this purpose. There's lots of examples, likex-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 indpkg
) and they'll look into the alternatives to give you the editor of choice. Forjava
, 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 exampleMoreover, the regular
/usr/bin
binaries are also symlinks. E.g.:So, no
PATH
has to be modified. It just uses symbolic links.While @gertvdjik's answer is a good explanation of how alternatives work at the lower level, it doesn't explicitly say how to revert the original state.
I find it easier to use the corresponding GUI
galternatives
which is available as a package. To install it, just run:Then managing alternatives becomes much easier. For java in particular, you have a lot of auxiliary binaries which you'll have to update and it's faster to overview them in the GUI.
And
update-alternatives
can create a group to switch easily. For examplejavaw
,java
andjavac
needs to go together ifjava
switches. Thenjavaw
andjavac
should be installed as slaves ofjava
. Oroc
andkubectl
(openshift client and kubernetes control) should go together, too. I have installed oc v3 and v4, and each version goes with its ownkubectl
. So I do:So oc3 and its kubectl are prioritized.