It is common for a server to have several different programs installed that all fulfil the same or similar function(s). Text editors are a good example – most servers have multiple text editors installed, such as vim, emacs, gedit.
Whilst this allows a user the choice of selecting a specific program, it can make it difficult for a program to know which (for example) text editor it should use if the programmer hasn’t defined a specific application. This is often a problem that effects automated tasks, such as cronjobs.
One solution to this is the alternatives system. Originally implemented on Debian, but available on Red Hat/CentOS and other non-Debian distros now, the alternatives system is used to maintain the symbolic links that are used to determine default commands. Where several commands or applications share the same or interchangeable functions, alternatives allows you to set up a generic name in the filesystem that can used to refer to a specific task, e.g. text editor. The server administrator can then select which specific command is then invoked.
An example file handle might be: /usr/bin/editor
This is not a direct symbolic link to the application, but a symbolic link to a name in the alternatives directory, e.g.
/etc/alternatives/editor
If we assume you have multiple text editors installed and want to set vim as the default, you would run:
update-alternatives –set editor /usr/bin/vim
If you now invoke editor, it will run vim.
It is possible to use alternatives to switch between different versions of programming languages too. For example, if your default installation of Java is set to OpenJDK, but you want to use Sun Java, you can use alternatives to ‘–set java’ to the installation path of the Sun Java binary. However, approach this option with caution, if you are not familiar with it’s use. Applications may not automatically pick up the changes (i.e. in this example, Tomcat might not pick up the Java change), which could result in downtime. If in any doubt, check with your hosting provider before making any changes.