Score:7

Difference between "select-editor" and "update-alternatives --config editor"

sd flag

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.

Score:9
jp flag

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.

geckels1 avatar
sd flag
I'm curious doesn't sudo use the root user? So wouldn't settings for sudo be found in /root? So the default editor for sudo would be found in /root/.selected_editor?
Raffa avatar
jp flag
@geckels1 That is a whole different question, but in short: no, [`sudo`](https://manpages.ubuntu.com/manpages/jammy/en/man8/sudo.8.html) grants you e.g. the execution rights of the owner of the executable file i.e. `root` but doesn't make you actually `root` ... Please see for example this post: https://unix.stackexchange.com/q/150718 that might shed some light on the matter ...Please see also related to this: https://askubuntu.com/a/1411528/968501
geckels1 avatar
sd flag
Thank you! That is very clarifying and what I was looking for. I was pretty sure there are nuances to sudo I wasn't aware of and this shows it.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.