Score:2

Why micro is not recognized as text editor in Ubuntu 22.04?

sc flag

I installed micro with sudo apt install micro on 22.04

I want to use visudo with micro.

export EDITOR=micro then next line visudo opens in nano. So, then I tried sudo update-alternatives --config editor this also does not show micro. (I removed vim-tiny to see if it removes it from the list) output:


  Selection    Path            Priority   Status
---------------------------------------------
* 0            /bin/nano        40        auto mode
  1            /bin/ed         -100       manual mode
  2            /bin/nano        40        manual mode

There is no micro but i have micro

I can run micro in the terminal by typing micro

How to fix this?

Score:1
jp flag

Why micro is not recognized as text editor in Ubuntu 22.04?

There appears to be no post install script included by the package maintainer to do that in the micro package:

$ apt source micro
Reading package lists... Done
NOTICE: 'micro' packaging is maintained in the 'Git' version control system at:
https://salsa.debian.org/go-team/packages/micro.git
Please use:
git clone https://salsa.debian.org/go-team/packages/micro.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 820 kB of source archives.
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/universe micro 2.0.9-1ubuntu0.22.04.2 (dsc) [2,664 B]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/universe micro 2.0.9-1ubuntu0.22.04.2 (tar) [812 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates/universe micro 2.0.9-1ubuntu0.22.04.2 (diff) [5,528 B]
Fetched 820 kB in 2s (369 kB/s)  
dpkg-source: info: extracting micro in micro-2.0.9
dpkg-source: info: unpacking micro_2.0.9.orig.tar.gz
dpkg-source: info: unpacking micro_2.0.9-1ubuntu0.22.04.2.debian.tar.xz
dpkg-source: info: using patch list from debian/patches/series
dpkg-source: info: applying 01-disable-commit-hash-and-date.patch
dpkg-source: info: applying use-original-fork.patch
$
$
$ find micro-2.0.9/ -name "*postinst" -print -exec cat {} \;
$

Compare that to e.g. the nano package:

$ apt source nano
Reading package lists... Done
NOTICE: 'nano' packaging is maintained in the 'Git' version control system at:
https://salsa.debian.org/debian/nano.git
Please use:
git clone https://salsa.debian.org/debian/nano.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 1,567 kB of source archives.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main nano 6.2-1 (dsc) [2,192 B]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main nano 6.2-1 (tar) [1,532 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/main nano 6.2-1 (asc) [833 B]
Get:4 http://archive.ubuntu.com/ubuntu jammy/main nano 6.2-1 (diff) [32.7 kB]
Fetched 1,567 kB in 2s (860 kB/s)
dpkg-source: info: extracting nano in nano-6.2
dpkg-source: info: unpacking nano_6.2.orig.tar.xz
dpkg-source: info: unpacking nano_6.2-1.debian.tar.xz
$
$
$ find nano-6.2/ -name "*postinst" -print -exec cat {} \;
nano-6.2/debian/nano.postinst
#!/bin/sh

set -e

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
    update-alternatives --install /usr/bin/editor editor /bin/nano 40 \
      --slave /usr/share/man/man1/editor.1.gz editor.1.gz \
      /usr/share/man/man1/nano.1.gz
    update-alternatives --install /usr/bin/pico pico /bin/nano 10 \
      --slave /usr/share/man/man1/pico.1.gz pico.1.gz \
      /usr/share/man/man1/nano.1.gz
fi

#DEBHELPER#
nano-6.2/debian/nano-tiny.postinst
#!/bin/sh

set -e

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
    update-alternatives --install /usr/bin/editor editor /bin/nano-tiny 0 \
      --slave /usr/share/man/man1/editor.1.gz editor.1.gz \
      /usr/share/man/man1/nano-tiny.1.gz
fi

#DEBHELPER#
$

How to fix this?

Set the environment variable momentarily like so:

sudo  EDITOR=micro visudo

Or add the editor to the Ubuntu alternatives system following the format:

update-alternatives --install <link> <name> <path> <priority>

like so:

sudo update-alternatives --install /usr/bin/editor editor /usr/bin/micro 40

so that you can later select it via:

sudo update-alternatives --config editor
For additional related informative explanation see also:

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

Raffa avatar
jp flag
@vanadium It is involved because the postinstall script that adds it to the alternatives system is missing for that certain version and that's the only way it can show in `update-alternatives --config editor` to be selected as an alternative ... I however checked https://salsa.debian.org/go-team/packages/micro/-/blob/debian/sid/debian/micro.postinst and they appear to have it, but not included in that version from Ubuntu repositories.
Score:0
cn flag

man visudo gives you a hint why it does not work:

sudo does not preserve the SUDO_EDITOR, VISUAL,
or EDITOR environment variables unless they are present in
the env_keep list or the env_reset option is disabled in the
sudoers file.  The default editor path is
/usr/bin/nano:/usr/bin/vim:/usr/bin/vi which can be set at
compile time via the --with-editor configure option.

To make it work in a simple way, use

sudo EDITOR=micro visudo

instead.

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.