我sudo apt install micro
在 22.04 上安装了 micro
我想将 visudo 与 micro 一起使用。
export EDITOR=micro
然后下一visudo
行在 nano 中打开。所以,然后我尝试了sudo update-alternatives --config editor
这个也没有显示 micro。(我删除了 vim-tiny 以查看它是否将其从列表中删除)输出:
Selection Path Priority Status
------------------------------------------------------------
* 0 /bin/nano 40 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
没有微信,但我有微信
我可以在终端中输入以下代码来运行 micromicro
如何解决这个问题?
答案1
为什么 micro 在 Ubuntu 22.04 中不能被识别为文本编辑器?
软件包维护者似乎没有在micro
软件包中包含执行此操作的后安装脚本:
$ 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 {} \;
$
将其与以下nano
包进行比较:
$ 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#
$
如何解决这个问题?
像这样暂时设置环境变量:
sudo EDITOR=micro visudo
或者按照以下格式将编辑器添加到 Ubuntu 替代系统:
update-alternatives --install <link> <name> <path> <priority>
像这样:
sudo update-alternatives --install /usr/bin/editor editor /usr/bin/micro 40
以便您以后可以通过以下方式选择它:
sudo update-alternatives --config editor
有关更多相关信息解释,另请参阅:
“select-editor” 和 “update-alternatives --config editor” 之间的区别
答案2
man visudo
提示一下为什么它不起作用:
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.
为了使其以简单的方式工作,使用
sudo EDITOR=micro visudo
反而。