[hllug] The Magic Behind "/etc/alternatives"

  • From: Lee Parmeter <geek@xxxxxxxxxxxxxx>
  • To: hllug@xxxxxxxxxxxxx
  • Date: Fri, 29 May 2009 15:32:59 -0500

Found this article today which sheds some light on "/etc/alternatives" and
how to manage the symbolic links easily.

THE MAGIC BEHIND /etc/alternatives

In some distros you'll find a folder called /etc/alternatives that
appears to be chock-full of commands. Look a little closer, though,
and you'll see that these are all symbolic links rather than actual
files -- in other words, they point to programs elsewhere in the

Open up a terminal and enter:

  cd /etc/alternatives

If you see an error message it means that your particular distro
doesn't support this system. Ubuntu and Debian derivatives should
always have it though. If the command works, enter 'ls' to show the
files inside. You should see a wealth of light blue filenames,
indicating that they're links (pointers to other files) rather than
actual program binaries.

So, what do they all mean? Well, we all know that Linux is about
freedom, especially the freedom to choose which software you run.
You never want the operating system to make assumptions as to which
program you want to start in a particular situation.

For instance, there are various different incarnations of the Vi
text editor. There's ViM, the most well-known flavour, there's Nvi,
a version usually supplied with BSD variants of Unix, and there are
many others as well. When you enter plain old 'vi' at a command
prompt, how does the operating system know which version of the
editor you want to use?

Well, enter:

  ls /usr/bin/vi

You'll see that /usr/bin/vi is a link to another file,
/etc/alternatives/vi. So enter:

  ls /etc/alternatives/vi

On our Ubuntu test system, that points to /usr/bin/vi.tiny, although
it may vary on yours. But you can see how the OS provides a flexible
means to allow a variety of programs with the same purpose on your

What if you want to change it, though? Here's how you can find out
which alternatives are available for a command:

  update-alternatives --display vi

This shows you the possible executable files you can link to
/etc/alternatives/vi -- in other words, what should be run when you
enter 'vi', Ignore the 'slave' bits; focus on the other lines with
'priority' in them. Say you want 'nvi' to be run when you enter
'vi'; you'd enter:

  update-alternatives --set vi /usr/bin/nvi

So that's how the system works. There are many other files in
/etc/alternatives to explore -- and see the manual page ('man

source: LINUX FORMAT NEWSLETTER -- #49, MAY 2009

Lee Parmeter

"When it comes to Vista: just say NO! If you're not ready for Linux, buy a
MAC!" - Lee Parmeter
"God is not a republican or a democrat nor is His government a democracy!"
- Lee Parmeter
Highland Lakes Linux User Group (HLLUG): http://www.hllug.org
HLLUG mailing list: http://www.freelists.org/list/hllug

Other related posts: