Skip to main content

Gentoo slots

So as a Gentoo sysadmin you would like to keep your system clean. But sometimes you also like to do some experiments. For example, you want the stable version of PHP on your system, but you want to check out the latest version. Gentoo allows you to pull in both 7.4 and 8.0 and use them along with each other.

The mechanism behind this is called "slots" and it's fairly simple to use. You just emerge the stable version as usual with:

emerge --ask --verbose dev-lang/php

Once that is finished, you actualy used the first slot. To pull in the latest version without removing the stable version, you do this:

emerge --ask --verbose =dev-lang/php-8*

Naturally you will first have to unmask this version by adding it to /etc/portage/package.accept_keywords

Now you can emerge version 8.* to the second slot. To select the version you want to use, you can use eselect:

eselect php list apache2

And you will see the two versions peacefully along with each other. In this example I used apache2, but you can choose between cli, apache2, fpm, cgi and phpdbg. You can even use different versions for each of them. To actually switch to the second slot you do:

eselect php set apache2 2

There is only one problem with these slots. When you run:

emerge --depclean --ask

Gentoo will want to remove the non stable and older versions. Luckily, you can exclude them with:

emerge --depclean --ask --exclude="php"

Another option is to add the versions you want to keep to you world file (/var/lib/portage/world)

=dev-lang/php-7*
=dev-lang/php-8*

Or you can preserve a specific version by emerging it with the --no-replace option.