How to: Create an entry into the update-alternative database
15. May 2020
howto
linux
terminal
There are situations where you have several programs for the same purpose or
when you want to call a program by a different name.
One such program is neovim, with the binary's name nvim
. I'm using it of
course as a drop in replacement of vim
, alas I want to call it by that name.
A natural way to accomplish this might be the creation of an alias in your shell
like alias vim='nvim '
, but this alias is only valid for the user, not
system wide. Therefore it is not available when called with sudo
.
For this reason (and many more) Debian introduced the concept of
update-alternative
. This, shortly spoken, allows for system wide aliases and
can be created with update-alternative --install link name path priority
. But
I'm always kind of confused what those parameters mean. So, here's a short
explanation:
- link: The fully qualified path to the alias name, which should be created
- name: The short name to call the binary
- path: The fully qualified path to the actual binary
- priority: In case there are several alternatives for this link/name you can choose a priority, how import this entry is.
As an example for neovim
sudo update-alternatives --install /usr/bin/vim vim /usr/bin/nvim 50
This means, that there should be a link under /usr/bin/vim
that links to the
real binary at /usr/bin/nvim
and can be called by the short name vim
. The
priority 50 is some magic number I'm using, you can choose for your self.
Another example: fd on Ubuntu
The find
alternative fd can be install via
apt on recent Ubuntu versions. But as the name fd
was already blocked by a
different package, the binary's name is fdfind
. To create a system wide alias
to fd
you can issue the following:
sudo update-alternatives --install /usr/bin/fd fd /usr/bin/fdfind 50
This creates at /usr/bin/fd
a link to the binary /usr/bin/fdfind
which can
be called with fd
. The great advantage to an alias is, that I can now also use
sudo fd
without any further configuration.