Linux and Unix Command Alternatives.

Deepak Gupta December 8, 2021
Updated 2021/12/08 at 4:38 AM

Generally, users of computerized systems are not interested in how they work as long as they fulfill their objective. In fact, at times the applications themselves do not take into account how a task works correctlyas long as the system calls are successful. Theoretically a system administrator Linux offers many system tools.

These tools are offered according to the function they execute in the place where the executable is located. This operation requires a explicit tracking of system versions. One way around these cumbersome processes is to use command alternatives.

Beginnings of command alternatives

Interestingly, the command alternatives emerged in the systems Unix and Linux as an alternative to using the commands used by default. This tool was developed in Perl language for the project Debian. It was considered a tool for the convenience of users and upgrade alternatives were named.

The American Open Source Company Red hat, rewrote the command without using the Perl language. This made it possible to spread this utility to systems based on Fedora and CentOS in addition to other Linux distributions.

When to use command alternatives

Linux / Unix command alternatives.

To understand when it is necessary to use command alternatives, let’s take a simple example. Suppose that on your system you have a command called “eda” whose function is to launch a text editor. This text editor has always been the editor of choice for a group of system users. Even these users have many customizations in said editor.

Nevertheless, recently users have stated that they want to include emojis within the text editor and currently it does not support encoding Unicode. What to do in such a dilemma?

Searching, it finds a version to the editor “eda” called “edaU” that supports Unicode encoding. The solution could be to replace the editor even knowing that most users are adapted to the “eda” editor. Any replacement you make would not change the fact that users prefer this editor.

The solution is quite simple, just should change the default binary with which the text editor is called with the command “eda” to the binary of the new editor: “edaU”.

In order to make this change, the most tempting way is to manually create a symbolic link. However, this solution would not hold up against package updates and would not work centrally.

The command alternatives it is a very useful one when using generic application names. In Linux, terms like java, (x) emacs (-nox), (n) vi (m), and IP tables are generally the first to have command alternatives.

For other more global terms, such as EDITOR or CC, command alternatives are not the best solution. System environment variables are defined for these terms in the root directory “/ Etc” or in “$ HOME /. profile “

How to create command alternatives

To explain how we will create an alternative command we will continue with the example previously exposed. In this we had a binary called “eda”. The new binary called “edaU” will replace the older one.

In the above example you must change el original command name. However, this is not always the case as the commands are not what users generally believe. For example, the binary for the java command is rarely found in the “/ usr / bin” directory directly.

If you need to rename a binary, the correct way to do it is not directly on the file. This action must be performed in the RPM spec file. In this way, the RPM that installs the command will provide the new name of the file.

In case the command needs to be removed anyway, it should be removed from the system package management and keep a custom version of the above command available.

To continue the example we will assume that the original binary “eda” has been renamed to “eda2”. At this moment we have two binaries, “eda2” and “edaU” to be associated with the same command “eda”. Assuming the text editor is in the style of the Gedit editor, a generic term for the alternative being created could be “uGedit”.

Parameters for creating the alternative

In order to create the alternative you must provide a series of essential parameters To make it work. First, you will need a location on the system where to put the symbolic link to the alternative.

On the other hand, you will need to give the alternative a name. In our example this name is uGedit, to highlight the fact that this is a reference name and not the name of a binary specifically.

Also, you must specify the binary to be executed when making calls to symbolic links. Finally, you need to specify a priority level that will indicate which alternative you prefer to use.

Command to create the alternative.

To create the alternative that points to our old binary, described in our problem, we must execute the following command:

$sudo alternatives --install /usr/bin/eda uGedit /opt/eda-legacy/eda2 1

For the new binary with support for encoding Unicode we will establish a higher priority as the preferred option when using the text editor.

$sudo alternatives --install /usr/bin/eda uGedit /usr/local/bin/edaU 99

The above commands create a symbolic link in the directory “/ Usr / bin / eda”, which points to “/ Etc / alternatives / eda”, and is in turn can point to “/ Opt / eda-legacy / edaU” or “/ Usr / local / bin / edaU”.

The reference for the user for these alternatives is the generic name that we previously introduced, that is, “uGedit”.

It is possible to choose the destination of the symbolic link of our alternative using the command “–config”. If we write in the terminal “$ Sudo alternatives –config uGedit” we will obtain as an answer:

There are 2 programs which provide 'uGedit'.
  Selection    Command


*+ 1           /usr/local/bin/edaU
   2           /opt/eda-legacy/eda2

In this terminal output we can see the priority established for the execution of the “uGedit” command, according to the one we established previously.

Delete an alternative command.

Sometimes the command alternatives constitute a long-term solution to a certain problem. However, they can be used to aid in transition to new applications. These would contribute positively to users adapting to the new tools without too radical changes.

To remove an alternative, you only need to type the command “–Remove-all” followed by the generic name that we have indicated to the alternative. In the example case, to eliminate the alternative created we would write in the terminal:

$ sudo alternatives --remove-all uGedi

This command will remove everything related to the alternative “uGedit“Including the symbolic link in the directory “/ Usr / bin” and “/ Etc / alternatives”.

In case you only want to eliminate one of the options referring to a specific alternative, you should use the command “–Remove”. In this case, you must specify the directory of the option you want to remove.

$ sudo alternatives --remove uGedit /opt/eda-legacy/eda2

With the execution of the previous command we would eliminate the option of using the old binary referring to our text editor.


The operating system Linux it is about the inclusion of everyone in its evolution. This system provides mechanisms to users where flexibility and free will play a fundamental role. The command alternatives are an example of how users or system administrators can benefit from the freedoms that Linux proposes.

The command alternatives have many more features that are not covered in this article. They even have the ability to link dependent components together when a specific alternative is executed. We invite you to continue delving into this topic, which will provide you with a powerful customization and configuration tool.

Share this Article
Leave a comment

Leave a Reply

Your email address will not be published.