Upcoming Hans

PLUG: 2018Sep13

ActivityPub: the decentralized social networking protocol allowing federated services like Mastodon, Pleroma, Plume, PixelFed, PeerTube and CloutStream to interact

What is?

/etc/alternatives is a system for determining default commands

update-alternatives - maintain symbolic links determining default commands

Long Form

       Different packages providing the same file need to do so cooperatively.
       In  other  words, the usage of update-alternatives is mandatory for all
       involved packages in such case. It is not  possible  to  override  some
       file  in  a package that does not employ the update-alternatives mecha‐
       nism.

History

originally created for debian

now available for most distributions

Features

Symlink chain

$ ls -l /usr/bin/pager
lrwxrwxrwx 1 root root 23 Nov 29  2016 /usr/bin/pager -> /etc/alternatives/pager
$ ls -l /etc/alternatives/pager
lrwxrwxrwx 1 root root 9 Nov 29  2016 /etc/alternatives/pager -> /bin/less
$

Grouping

$ ls -l /etc/alternatives/pager*
lrwxrwxrwx 1 root root  9 Nov 29  2016 /etc/alternatives/pager -> /bin/less
lrwxrwxrwx 1 root root 29 Nov 29  2016 /etc/alternatives/pager.1.gz -> /usr/share/man/man1/less.1.gz

Examples: in use

visudo uses editor to determine which text editor to use

Examples: list

$ update-alternatives --list x-session-manager
/usr/bin/startkde
$
$ update-alternatives --list editor
/bin/ed
/bin/nano
/usr/bin/vim.gtk
/usr/bin/vim.nox
/usr/bin/vim.tiny
$

Examples: display details

$ update-alternatives --display x-session-manager
x-session-manager - auto mode
  link best version is /usr/bin/startkde
  link currently points to /usr/bin/startkde
  link x-session-manager is /usr/bin/x-session-manager
/usr/bin/startkde - priority 40
$

Examples: display with group

$ update-alternatives --display pager
pager - auto mode
  link best version is /bin/less
  link currently points to /bin/less
  link pager is /usr/bin/pager
  slave pager.1.gz is /usr/share/man/man1/pager.1.gz
/bin/less - priority 77
  slave pager.1.gz: /usr/share/man/man1/less.1.gz
/bin/more - priority 50
  slave pager.1.gz: /usr/share/man/man1/more.1.gz
/usr/bin/pg - priority 10
  slave pager.1.gz: /usr/share/man/man1/pg.1.gz
$

Examples: local override

$ update-alternatives --config pager
There are 3 choices for the alternative pager (providing /usr/bin/pager).

  Selection    Path            Priority   Status
 ------------------------------------------------------------
* 0            /bin/less        77        auto mode
  1            /bin/less        77        manual mode
  2            /bin/more        50        manual mode
  3            /usr/bin/pg      10        manual mode

Press <enter> to keep the current choice[*], or type selection number:
$

Examples: return to default

$ update-alternatives --auto pager
$

Examples: non-interactive mode

# update-alternatives --set pager /bin/more
update-alternatives: using /bin/more to provide /usr/bin/pager (pager) in manual mode
#

Examples: list alternatives

update-alternatives --get-selections

Examples: roll your own

# update-alternatives --install /usr/bin/pager pager /bin/cat 99 --slave /usr/share/man/man1/pager.1.gz pager.1.gz /usr/share/man/man1/cat.1.gz
#

Examples: roll your own caution

# update-alternatives --install /bin/pager pager /bin/cat 99
update-alternatives: renaming pager link from /usr/bin/pager to /bin/pager
#

Examples: unroll your own

# update-alternatives --remove pager /bin/cat
#

Examples: other CLI options

Examples: alternatives

Special Handling: java

       update-java-alternatives updates all alternatives belonging to one run‐
       time  or development kit for the Java language.  A package does provide
       these information of it's alternatives in /usr/lib/jvm/.<jname>.jinfo.

Other Mechanisms

Other Mechanisms: environmental variable

$ EDITOR=/usr/bin/vim visudo

Other Mechanisms: sensible-utils

 This package provides a number of small utilities which are used
 by programs to sensibly select and spawn an appropriate browser,
 editor, or pager.

Other Mechanisms: aliases

$ alias pager=/bin/cat
$ type pager
pager is aliased to `/bin/cat'
$ unalias pager
$ type pager
pager is /usr/bin/pager
$

Contacting der.hans

Thank you!

Resources