update-alternatives broken and php no longer found in cmd

Viewed 299

I tried to switch the php version from 7.4 to 8.0 on my ubuntu operating system and wanted to use update-alternatives. I entered the following command, which broke everything: sudo update-alternatives --install /etc/alternatives/php php /usr/bin/php8.0 1

This command must have been faulty, because now php is no longer found through cmd and any update-alternatives command returns update-alternatives: error: cannot stat file '/etc/alternatives/php': Too many levels of symbolic links

It must have something to do with the php-symlink under /etc/alternatives. It is marked as Link (broken) and the Link target is /etc/alternatives/php which is the file itself, brobably resulting in an infinite loop. Deleting the file and running update-alternatives again recreates the file, but with the same broken link target.

Any information on how to fix this is appreciated. Thanks!

1 Answers

I was recommended to run update-alternatives --auto php or update-alternatives --config php which did not work for me. What worked however was this:

  1. I manually deleted the faulty symlink under /etc/alternatives/php
  2. I ran sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.0 1 which, in contrast to the other commands, created a new and working symlink to the corresponding php version.

This restored normal functionality of update-alternatives and made me able to use php from cmd again.

Related