Ubuntu – How does APT deal with different programs with the same name

alternativesaptpackage-managementUbuntu

I decided to finally learn vi and as I was doing that I realized that vi wasn't behaving as I expected. I learned from another post that this was because, on Ubuntu, vim-tiny is installed by default.

After I learned that I chose to install the full version of vim using the following command:

sudo apt-get install vim

After I did that I became curious about a number of things:

  1. I noticed that vi and vim commands are now associated with the full version of vim and not vim-tiny. How does this happen? (i.e. How does the name look-up work?)
  2. How do I explicitly execute either vim-tiny or full vim?
  3. How does Linux/Ubuntu/apt manage libraries and executables with name clashes? How about different versions?

I'm working on Ubuntu Server 12.04 LTS.

Best Answer

On Debian-derivatives, it's handled through the alternatives system:

$ ls -l /usr/bin/vim
lrwxrwxrwx 1 root root 21 Jun 11  2010 /usr/bin/vim -> /etc/alternatives/vim
$ ls -l /etc/alternatives/vim
lrwxrwxrwx 1 root root 18 Jun 11  2010 /etc/alternatives/vim -> /usr/bin/vim.gnome

The package post install script (the thing that runs when dpkg says "configuring package X") told the alternative system about a new alternative for vim. The new alternative had a higher priority, so it was picked.

You can run them directly as vim.tiny, vim.full, vim.gnome, etc.

You can override the default using the update-alternatives command.

(Actually, I think vim.tiny works somewhat as a special case, as its not really intended to be used except when space is at a huge premium. At least, it doesn't show as an alternative here.)

Related Question