Fixing "A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist"
Problem Statement
When trying to run dotnet commands on Ubuntu 22.04 after an update or installation, you encounter a critical error preventing any operations:
A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not existThis issue occurs due to conflicts between competing .NET Core installation sources:
- Official Microsoft packages (
packages.microsoft.com) - Ubuntu's native repository packages (
archive.ubuntu.comandsecurity.ubuntu.com) - Snap or other installation methods
The core problem stems from mixed installations from different sources, causing incomplete or conflicting SDK installations. This often happens after:
- OS updates (particularly Ubuntu 20.04 → 22.04 migrations)
- Installing newer .NET versions alongside existing ones
- Having both Microsoft and Ubuntu repositories active simultaneously
Recommended Solution
Complete Removal and Reinstallation (Ubuntu Packages)
RECOMMENDED APPROACH
Starting with .NET 9, Microsoft no longer publishes .NET packages for platforms that package .NET themselves (like Ubuntu). Using Ubuntu packages is now the recommended long-term solution.
# Remove all conflicting packages
sudo apt remove dotnet* aspnetcore* netstandard* --purge
# Remove Microsoft repo sources
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
# Update package lists
sudo apt update
# Install desired SDK version
sudo apt install dotnet-sdk-8.0 # Replace 8.0 with your target versionAlternative: Prioritize Microsoft Packages
Use this approach if you need specific versions not available in Ubuntu repositories:
# Create APT preferences file
sudo nano /etc/apt/preferences.d/99microsoft-dotnet.prefPackage: dotnet* aspnetcore* netstandard*
Pin: origin "packages.microsoft.com"
Pin-Priority: 999
Package: dotnet* aspnetcore* netstandard*
Pin: origin "archive.ubuntu.com"
Pin-Priority: -10
Package: dotnet* aspnetcore* netstandard*
Pin: origin "security.ubuntu.com"
Pin-Priority: -10# Register Microsoft repository
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
# Update and install
sudo apt update
sudo apt install dotnet-sdk-8.0Verification Steps
After either installation method, confirm success with:
dotnet --info
dotnet --list-sdksAdditional Troubleshooting
FOR MICROSOFT REPO USERS
If using Microsoft packages, ensure no Ubuntu .NET packages are installed. Conflicts will resurface otherwise.
Special Cases
Broken dependencies resolution
If apt install fails after removal:
sudo apt upgrade
sudo apt update --fix-missing
sudo apt install -f dotnet-sdk-8.0Snap installations
If using Snap (.NET 7+ default):
sudo snap remove dotnet-sdk
sudo snap install dotnet-sdk --classicMacOS Specific Fix (via MacPorts)
sudo port install dotnet-cli
sudo port install dotnet-runtime-8
sudo port install dotnet-sdk-8MMSQL Repository Conflicts
If you have SQL Server tools installed:
sudo rm -f /etc/apt/sources.list.d/mssql-release.list
sudo apt purge dotnet*Explanation
The /usr/share/dotnet/host/fxr folder is critical for managing .NET runtime versions. When package sources conflict:
- Partial installations occur where runtime assets are missing
- Package managers overwrite each other's files
- Symbolic links become broken or misdirected
The solutions work by:
- Eliminating mixtures - Full removal ensures no package fragments remain
- Enforcing source consistency - APT pinning (999 priority) forces one source to dominate
- Isolating dependencies - Each method keeps dependencies tied to one ecosystem
FUTURE PROOFING
As distributions mature their .NET packages, clean integration with native package managers will become the primary installation method. Stick to your distribution's packages unless you need specific features from Microsoft builds.