Gentoo - Protect your running PHP version from emerge depclean

Now that I’ve been running this blog on Gentoo Linux for a while, I’ve discovered a few new potential gotchas when failing to pay attention while interacting with Portage. The latest addition to my list was nearly removing my running PHP installation with emerge --depclean.

After the PHP 7.1 series got merged, my running PHP version (7.0.25) got marked for removal upon running <em>emerge --depclean </em>as shown on the image below.

Depclean marking PHP 7.0

Always study the list of packages to be cleaned for any obvious mistakes.

Gentoo is providing version slotting for PHP, so running multiple PHP versions is both supported and a major advantage of using Gentoo. To preserve the PHP 7.0 series I’ll add it to my world set (explicitly installed and required software). As PHP is slotted, I believe the most appropriate approach would be to use <em>emerge --noreplace</em> with the PHP slot version. The following command will add the PHP 7.0 series to the world set:

# Notice the colon which signifies the slot notation 
emerge -av --noreplace dev-lang/php:7.0  
Add PHP 7.0 to the world set

Listing installed PHP versions and adding PHP 7.0 to the world set.

As seen from my world file, the PHP 7.0 series will now be omitted when running depclean:

cat /var/lib/portage/world | grep php
dev-lang/php
dev-lang/php:7.0

To identify all available slots for PHP, the following command will suffice (includes PHP version and slot):

equery list -p dev-lang/php
for php in dev-lang ...
[-P-] [  ] dev-lang/php-5.6.32:5.6
[IP-] [  ] dev-lang/php-7.0.25:7.0
[-P-] [ ~] dev-lang/php-7.0.26:7.0
[IP-] [  ] dev-lang/php-7.1.11:7.1
[-P-] [ ~] dev-lang/php-7.1.12:7.1
[-P-] [ ~] dev-lang/php-7.2.0:7.2
Roger Comply avatar
Roger Comply
Thank you for reading!
Feel free to waste more time by subscribing to my RSS feed.