Managing Multiple Program Versions with Update-Alternatives

parallel versionsAfter installing Python 3.9 side-by-side with Python 3.6, one of our friends observed, “I noticed that the newer version, Python 3.9, became the default on my IBM i system. How does the default version get set?” I thought this was a good time to explain how IBM uses the update-alternatives program to set the default version of Python and other open source software packages.

Update-alternatives helps organize multiple versions of open source packages. Examples: different versions of the same tool (like Python) or different implementations of the same standard (like a mailer or C compiler). Update-alternatives is the standard way to manage parallel versions on Linux systems, and now it’s used on IBM i, too.

Packages that support update-alternatives will call it to add and remove alternative versions as they’re installed or removed, so you don’t need to worry about it. When a package is enrolled into the alternatives system (and possibly becomes default), you’ll see messages like this as they install:

update-alternatives: using /QOpenSys/pkgs/bin/python3.9 to provide /QOpenSys/pkgs/bin/python3 (python3) in auto mode
update-alternatives: using /QOpenSys/pkgs/bin/python3.9 to provide /QOpenSys/pkgs/bin/python (python) in auto mode

If you want to see your alternatives, or to change the defaults, the easiest way is to run update-alternatives from a PASE shell and pass the –config flag with the program name you’re interested in. This will provide a list of possibilities, along with what’s being used, and choices to change it:

$ update-alternatives --config python
There are 3 choices for the alternative python (providing /QOpenSys/pkgs/bin/python).

  Selection    Path                          Priority   Status
* 0            /QOpenSys/pkgs/bin/python3.9   309       auto mode
  1            /QOpenSys/pkgs/bin/python2.7   207       manual mode
  2            /QOpenSys/pkgs/bin/python3.6   306       manual mode
  3            /QOpenSys/pkgs/bin/python3.9   309       manual mode

Press  to keep the current choice[*], or type selection number:

Note the priority value; in automatic mode, the package with the highest priority when enrolled becomes the preferred alternative automatically.

To list what alternatives can be managed, use the –get-selections flag:

$ update-alternatives --get-selections
libpgtypes                     auto     /QOpenSys/pkgs/lib/postgresql12/lib/
libpq                          auto     /QOpenSys/pkgs/lib/postgresql12/lib/
mta                            auto     /QOpenSys/pkgs/bin/msmtp
node                           auto     /QOpenSys/pkgs/lib/nodejs12/bin/node
postgresql-devel               auto     /QOpenSys/pkgs/lib/postgresql12/bin/pg_config
python                         auto     /QOpenSys/pkgs/bin/python3.9
python3                        auto     /QOpenSys/pkgs/bin/python3.9

Not all packages provide support for update-alternatives; this is usually due to limitations in package management. For packages that aren’t managed through update-alternatives, you can run multiple versions in parallel by installing them in chroot containers.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.