Update Alternative

We will use Update Alternatives here, which is explained best by the first 2 man pages paragraphs (http://manpages.ubuntu.com/manpages/hardy/man8/update-alternatives.8.html):

Check out the lesson on Update Alternatives Below.

Update update-alternatives of vim to new vim (statically compiled vim)

In the mean time here is an example of updating all of the alternatives/links of every editor to point at a new vim you compiled. Note that this only works if all of the editors have a fancy keyword like “vim.tiny” or “vim.basic” or “vim” and we want to change them all to “vim.static” (our new one).

Lets say you followed instructions here (https://raymii.org/s/blog/Statically_cross_compiled_vim_for_x86_x86-64_and_mips.html) to make a new Vim compilation (such as a statically linked one as in the link, so that it doesnt depend on libraries – note it might still depend on glibc according to this link: https://github.com/ericpruitt/static-vim )


Ideally as a last step you would like to install it.
Im assuming your in the vims source code src folder (that you compiled in). So your in vim/src. And in there is a compiled version of vim. (NOTE as per the instructions I assumed you didnt run “make install”, which would do similar steps to below).

So now you have your new vim here /usr/bin/vim.static

Now you will notice that most of your apps point to an old vim.

NOTE: the above output lists all of the alternatives and their current active targets. For example the alternative “editor” (which is located in /usr/bin/editor, you specify this upon installation of alternative) points to “/usr/bin/vim.basic”. so that means “/usr/bin/vim.basic” is launched everytime “editor” is ran. Also note that “usr/bin/vim.basic” is the current target of “editor” because “vim.basic” has the current highest priority between the other targets (vim.tiny, vim.basic). If we were to install a new target to editor with a highest priotity it would be set (launching editor would launch the new target). Note that an alternative can also be set to another target (not just its highest priority target) by using –config or –set, this will change its status from an auto (automatic) alternative to a manual alternative. With a manual alternative the current active target is the one you set, and not necessarily the one with the highest priority.

To update one of the apps, we just need to follow the 2 steps. For example lets say we want to change “editor” (which is opened by things like “crontab -e”, the crontab editor – so we will set the crontab editor to our new vim) to our new “vim.static”. First we install vim.static as an available “alternative” for editor. editor has many different alternative one of them is vim.basic, one of them is nano, one of them is vim.tiny. By default we also install a priority number, the highest the better (it picks it).

Step 1 install vim.static as an alternative for editor with priority 50:


Step 2 set vim.static as the current alternative for editor (meaning when “editor” is run “vim.static” will run):


Then press the # associated for /usr/bin/vim.static and the enter key
NOTE: If you picked a high enough priority on step 1, you don’t even need to do step 2, as the default editor is set as the highest one in an auto alternative. (more on auto and manual alternatives below in lesson section)

Change all vim.basic to point to vim.static

Now lets change all of the things that point at vim.basic to point at vim.static.


Lesson on Update Alternative

To make a your own alternative program, such as “kosedit”, which will launch one of your many editors (which ever one is currently set). You can do this:


Even though we processed vim.static last, it is now the active kosedit. The higher priority is set as the current one in auto mode (as we can see each alternative is by default in “auto” mode).


So now everytime I call kosedit it will launch /usr/bin/vim.basic. kosedit will work because its in our PATH (/usr/bin). Whats the point of all of this? Well hopefully kosedit is less typing then vim.basic. Also this helps point many editors that other programs use towards your edit. For example we all know that the crontab editor uses editor (/usr/bin/editor), so we could either “cp /usr/bin/vim.static /usr/bin/editor” but thats not a pretty way, or we could “ln -s /usr/bin/vim.static /usr/bin/editor”, but instead there is a program for this, so lets just use it (update-alternatives).

If I reinstall vim.static with priority 50 it will be the defaults


How to manually pick an alternative?

Then I type 0,1,2,3 to pick which ever one. That will change my status to “static”

For example, I picked 1, vim.basic:

How to go auto pick an alternative (switch from manual to auto)?

Now the highest priority alternative will win. Which is vim.static.

Leave a Reply

Your email address will not be published. Required fields are marked *