Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

dotnet stops with 'the folder host/fxr does not exist' on Ubuntu

ErrorA fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist

Short answer

This error nearly always means .NET packages came from two different package feeds, usually Ubuntu's own and Microsoft's, and each put files in a different place. Remove every dotnet package, keep one feed only (pin the other one off), then reinstall from that feed.

  • Applies to .NET 8 and 10, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List which .NET packages are installed and which feed each one came from. If you see the same package family offered by both Ubuntu and packages.microsoft.com, you have found the cause.

    dotnet --info
    apt-cache policy '?name(dotnet.*)'
    ls -d /usr/lib/dotnet /usr/lib64/dotnet /usr/share/dotnet 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1Both /usr/share/dotnet and /usr/lib64/dotnet exist, and apt-cache policy lists dotnet packages from packages.microsoft.com next to ones from an Ubuntu archiveUbuntu's .NET packages and the Microsoft feed are both installedFix
    2. 2The error appears after you added the Microsoft feed or the Ubuntu .NET backports repository to get a version that is not in the default Ubuntu archiveYou need a .NET version Ubuntu does not ship, and both feeds still answerFix
    3. 3dotnet --info points at a folder you extracted yourself, and the error names a different folder such as /usr/share/dotnetThe dotnet on your PATH is a manual install that was never set up as oneFix

What does the error look like?

  • A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist
  • A fatal error occurred. The required library libhostfxr.so could not be found.
  • A fatal error occurred, the folder [/usr/share/dotnet/host/fxr] does not contain any version-numbered child folders

Cause 1 of 3

Ubuntu's .NET packages and the Microsoft feed are both installed

1Check

Microsoft documents this as a package mix-up: two repositories supply .NET, put files at different paths and are built differently. If you only wanted Ubuntu's packages, the Microsoft feed is the one to switch off.

apt-cache policy '?name(dotnet.*)' | grep -E 'packages.microsoft.com|ubuntu'
ls /etc/apt/sources.list.d/ | grep -i microsoft

2Fix

Remove all .NET packages, then stop the Microsoft feed from supplying them. If you use that feed for other software (PowerShell, for example), pin only the .NET names off it. If you do not, delete the feed file. Then install again from Ubuntu.

sudo apt remove 'dotnet*' 'aspnet*' 'netstandard*'

# Option A: you need the Microsoft feed for other packages.
# Create /etc/apt/preferences (if missing) and add:
#   Package: dotnet* aspnet* netstandard*
#   Pin: origin "packages.microsoft.com"
#   Pin-Priority: -10

# Option B: you do not need the Microsoft feed at all.
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo apt update

sudo apt-get install -y dotnet-sdk-8.0

3Verify

The SDK is listed and a new project builds.

dotnet --list-sdks
dotnet new console -o /tmp/fxr-check && dotnet run --project /tmp/fxr-check

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

You need a .NET version Ubuntu does not ship, and both feeds still answer

1Check

Microsoft's rule is to use one source per machine. Here the extra version comes from a second source, so the distribution's own .NET packages must be switched off, not the other way round. On Ubuntu 22.04 and 24.04, the backports repository is the documented way to get .NET 9 and 10 where they are not in the default archive.

apt-cache policy '?name(dotnet.*)' | grep 'ppa.launchpadcontent.net/dotnet/backports' | sort -u
sudo apt-get install -y dotnet-sdk-9.0 --dry-run | head

2Fix

Remove all .NET packages. Either pin the other source's .NET packages to -10 in /etc/apt/preferences (one stanza per origin, for example archive.ubuntu.com and security.ubuntu.com), or add the backports repository and install from it alone, then reinstall.

sudo apt remove 'dotnet*' 'aspnet*' 'netstandard*'
sudo add-apt-repository ppa:dotnet/backports
sudo apt-get update && sudo apt-get install -y dotnet-sdk-9.0

3Verify

Only one origin remains for the dotnet packages and the host files are found.

apt-cache policy dotnet-sdk-9.0
dotnet --info

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 3

The dotnet on your PATH is a manual install that was never set up as one

1Check

A tarball or install-script copy does not live under /usr/share/dotnet. Its folder must be in DOTNET_ROOT and on PATH, otherwise the launcher looks in the default location and finds nothing.

echo "$DOTNET_ROOT"
which -a dotnet

2Fix

Point DOTNET_ROOT at the folder you installed into and put it on PATH, in your shell profile so it survives a new terminal.

export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

3Verify

A new terminal reports the SDK from that folder.

dotnet --list-sdks

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Install .NET from one source per machine, and write down which one it is.
  • On Ubuntu 24.04, do not add the Microsoft feed just for .NET: Microsoft says its repository no longer contains .NET packages for that release.
  • Run dotnet --list-sdks and dotnet --list-runtimes after any package change, before you build.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.