I manages many server using Ubuntu Server for hosting dotnet apps as service. Recently, they failed one by one. The dotnet services on them cannot start. When typing dotnet –version, it reports
A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist.
The whole problem is we installed the dotnet very early. In that time, we need to install the packages-microsoft-prod due to lack of official support of dotnet from ubuntu. But now it’s changed. Recently, dotnet is listed in the Ubuntu package manager feeds. That leads into the conflict which cause the services cannot start.
The way to fix is easy:
First, lists all installed packages using
sudo apt list --installed | grep dotnet
You may see some like dotnet-host dotnet-hostfxr-6.0 dotnet-runtime-6.0.
Now, removes those package listed using
sudo apt purge dotnet-host dotnet-hostfxr-6.0 dotnet-runtime-6.0
Also, packages-microsoft-prod is need to be purged also. To be mentioned, it must be purged instead of removed, which will remove the config file which is very the reason cause the conflicts.
sudo dpkg -P packages-microsoft-prod
Now, we can install the dotnet runtime from ubuntu official feeds using some like
sudo apt update && \
sudo apt install -y aspnetcore-runtime-6.0
Hope this can save your day.