8

I'm looking at how Ubuntu selects a default editor, and I notice that to set the default editor for editing crontabs, I use select-editor while to set the default editor for visudo I use update-alternatives --config editor. Does anyone know the specific difference between these two? There's a lot of documentation explaining each one individually, but I haven't been able to figure out the difference between the two or why I have to set both.

For completeness, I want to note I know how to set the default editor by setting the EDITOR and VISUAL environment variables.

geckels1
  • 183

1 Answers1

9

select-editor is a per user selector ... It helps you select your default sensible-editor from all installed editors ... It affects the file ~/.selected_editor i.e. for example on my system:

$ cat ~/.selected_editor
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/bin/nano"

Please see man select-editor:

select-editor provides a coherent mechanism for selecting and storing a preferred sensible-editor on a per-user basis. It lists the available editors on a system and interactively prompts the user to select one. The results are stored as SELECTED_EDITOR variable in ~/.selected_editor, which is sourced and used by sensible-editor command. SELECTED_EDITOR variable is overridden by the VISUAL and EDITOR environment variables.

update-alternatives, on the other hand, is a system-wide selector ... It helps you set the default behaviors e.g. editor that a system command calls ... visudo is such a command ... It does so by handling which editor /usr/bin/editor calls ... As a symbolic link i.e. for example on my system:

$ ls -l /usr/bin/editor /etc/alternatives/editor
lrwxrwxrwx 1 root root  9 Jan  8  2022 /etc/alternatives/editor -> /bin/nano
lrwxrwxrwx 1 root root 24 Jan  8  2022 /usr/bin/editor -> /etc/alternatives/editor

Please see man update-alternatives:

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.

Raffa
  • 34,963