Skip to main content

Ubuntu update-alternatives command

I just found one of the most handy features in Ubuntu I think I have ever come accross:

update-alternatives

I installed EMMS (Emacs Multi Media System) so I could play my music from within emacs. I use emacs-snapshot which is the latest beta version of emacs (interesting to note that the beta is more stable than most official releases of software that runs on an OS from Redmond, Washington, but I digress). I just sudo aptitude install emms. A few minutes later it was installed.

I fired up emacs and much to my surprise it was emacs 22. Huh?? where did 23 go? Time to see what was going on here.

ls -l /usr/bin | grep emacs

which returned:


-rwxr-xr-x 1 root root 5548 2008-09-05 17:47 b2m.emacs22
-rwxr-xr-x 1 root root 5556 2008-10-13 16:36 b2m.emacs-snapshot
-rwxr-xr-x 1 root root 90712 2008-09-05 17:47 ctags.emacs22
-rwxr-xr-x 1 root root 90752 2008-10-13 16:36 ctags.emacs-snapshot
-rwxr-xr-x 1 root root 38636 2008-09-05 17:47 ebrowse.emacs22
-rwxr-xr-x 1 root root 38644 2008-10-13 16:36 ebrowse.emacs-snapshot
lrwxrwxrwx 1 root root 23 2009-02-01 20:46 emacs -> /etc/alternatives/emacs
lrwxrwxrwx 1 root root 25 2009-02-05 21:24 emacs22 -> /etc/alternatives/emacs22
-rwxr-xr-x 1 root root 5522648 2008-09-05 17:47 emacs22-x
lrwxrwxrwx 1 root root 29 2009-02-01 20:46 emacsclient -> /etc/alternatives/emacsclient
-rwxr-xr-x 1 root root 13972 2008-09-05 17:47 emacsclient.emacs22
-rwxr-xr-x 1 root root 18188 2008-10-13 16:36 emacsclient.emacs-snapshot
lrwxrwxrwx 1 root root 32 2009-02-01 20:46 emacs-snapshot -> /etc/alternatives/emacs-snapshot
-rwxr-xr-x 1 root root 14165276 2008-10-13 16:36 emacs-snapshot-gtk
lrwxrwxrwx 1 root root 18 2009-02-01 20:46 emacs-snapshot-x -> emacs-snapshot-gtk
-rwxr-xr-x 1 root root 86616 2008-09-05 17:47 etags.emacs22
-rwxr-xr-x 1 root root 86688 2008-10-13 16:36 etags.emacs-snapshot
-rwxr-xr-x 1 root root 7365 2008-09-05 17:46 grep-changelog.emacs22
-rwxr-xr-x 1 root root 7281 2008-10-13 16:34 grep-changelog.emacs-snapshot
-rwxr-xr-x 1 root root 4067 2008-09-05 17:46 rcs-checkin.emacs22
-rwxr-xr-x 1 root root 3971 2008-10-13 16:34 rcs-checkin.emacs-snapshot

What's this? lrwxrwxrwx 1 root root 23 2009-02-01 20:46 emacs -> /etc/alternatives/emacs

ls /etc/alternatives

Shows a README file

cat /etc/alternatives/README
Please read the update-alternatives(8) man page for information on this
directory and its contents.

Ah ha! so this is a new feature to Debian/Ubuntu.

I read the man page
man update-alternatives

From the man page it says to run this command to change the configuration:
update-alternatives --config emacs


There are 2 alternatives which provide `emacs'.

Selection Alternative
-----------------------------------------------
* 1 /usr/bin/emacs-snapshot
+ 2 /usr/bin/emacs22

So it all comes down to Ubuntu can run different versions of applications side by side. Using updae-alternatives allows you the user to switch between the version you use most often so you don't have to constantly type emacs-snapshot or emacs-22 you just use emacs and BAM your done. Should I need the older stable version I can just type in emacs22 and that will get me the old version.

Brilliant! Absolutely BRILLIANT!!! Way to go Ubuntu/Debian devs!!!!