Skip to content

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 exist

This issue occurs due to conflicts between competing .NET Core installation sources:

  1. Official Microsoft packages (packages.microsoft.com)
  2. Ubuntu's native repository packages (archive.ubuntu.com and security.ubuntu.com)
  3. 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

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.

bash
# 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 version

Alternative: Prioritize Microsoft Packages

Use this approach if you need specific versions not available in Ubuntu repositories:

bash
# Create APT preferences file
sudo nano /etc/apt/preferences.d/99microsoft-dotnet.pref
text
Package: 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
bash
# 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.0

Verification Steps

After either installation method, confirm success with:

bash
dotnet --info
dotnet --list-sdks

Additional 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:

bash
sudo apt upgrade
sudo apt update --fix-missing
sudo apt install -f dotnet-sdk-8.0

Snap installations

If using Snap (.NET 7+ default):

bash
sudo snap remove dotnet-sdk
sudo snap install dotnet-sdk --classic

MacOS Specific Fix (via MacPorts)

bash
sudo port install dotnet-cli
sudo port install dotnet-runtime-8
sudo port install dotnet-sdk-8

MMSQL Repository Conflicts

If you have SQL Server tools installed:

bash
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:

  1. Eliminating mixtures - Full removal ensures no package fragments remain
  2. Enforcing source consistency - APT pinning (999 priority) forces one source to dominate
  3. 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.