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

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
3 min

banner

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

The error "A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist" occurs when you install .NET (Core) using the Microsoft APT and your installation clashes with the one from the Ubuntu repository.

To resolve the error, remove all existing .NET packages from your machine and only use the Microsoft APT repository.

fatal error ocurred the folder does not exist

  1. Open your terminal and run the following command to remove all .NET packages from your machine.
shell
sudo apt remove dotnet*

If you use zsh, you might get an error that "no matches are found". In this case, wrap the dotnet* pattern in single quotes.

shell
# for ZSH (if you get an error) sudo apt remove 'dotnet*'

remove dotnet packages

Make sure to type Y and press Enter if you get prompted for confirmation.

  1. Now, run the following command to remove all .NET standard packages.
shell
sudo apt remove netstandard* # for ZSH (if you get an error) sudo apt remove 'netstandard*'

remove netstandard packages

  1. Run the following command to remove all ASP.NET Core packages from your machine.
shell
sudo apt remove aspnetcore* # for ZSH (if you get an error) sudo apt remove 'aspnetcore*'

remove asp net core packages

  1. Create a microsoft-dotnet.pref file in your /etc/apt/preferences.d directory.
shell
# using gedit sudo gedit /etc/apt/preferences.d/99microsoft-dotnet.pref

The command above uses gedit, but you can also use nano.

shell
# using nano sudo nano /etc/apt/preferences.d/99microsoft-dotnet.pref

Or vim.

shell
# using Vim sudo vim /etc/apt/preferences.d/99microsoft-dotnet.pref

Add the following to your /etc/apt/preferences.d/99microsoft-dotnet.pref file.

/etc/apt/preferences.d/99microsoft-dotnet.pref
Package: * Pin: origin "packages.microsoft.com" Pin-Priority: 1001

update your microsoft dotnet pref file

Files in the /etc/apt/preferences.d/ directory should have a .pref extension.

Save the file and close your text editor.

Now run the following commands to install the .NET Core SDK.

shell
# API transport for downloading via HTTPS sudo apt install apt-transport-https # Download package information sudo apt update # Install the .NET Core SDK sudo apt install dotnet-sdk-6.0

Type y and press Enter if you get prompted for confirmation.

install dotnet sdk

Once you install the .NET Core SDK, you will be able to issue dotnet commands without getting any errors.

shell
dotnet --version dotnet --help

run dotnet commands without getting errors

The approach above uses the Microsoft .NET packages because they are regularly updated.

# Using the Ubuntu .NET packages instead of Microsoft's packages

If you decide to use the Ubuntu packages, you have to delete the Microsoft repository.

This is not recommended because the repository contains other packages that you might be using, e.g. Microsoft SQL Server.

The Microsoft repository is also kept up-to-date.

However, if you decide to install and use the .NET packages from the Ubuntu repositories:

  1. Remove all .NET packages from your machine.
shell
# 1) remove .NET packages sudo apt remove 'dotnet*' # 2) remove .NET standard packages sudo apt remove netstandard* # 3) remove all ASP.NET Core packages sudo apt remove aspnetcore*

If you get prompted for confirmation, type Y and press Enter.

  1. If you previously created a /etc/apt/preferences.d/99microsoft-dotnet.pref file, delete it by running the following command.
shell
sudo rm -rf /etc/apt/preferences.d/99microsoft-dotnet.pref

remove microsoft dotnet pref file

  1. Remove the Microsoft repository.
NOTE: if you use Microsoft SQL Server and other packages from their repository (e.g. PowerShell), you shouldn't use this approach. Instead, use the approach from the previous subheading.
shell
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
  1. Install the .NET Core SDK.
shell
# Download package information sudo apt update # Install the .NET Core SDK sudo apt install dotnet-sdk-6.0

install dotnet sdk from ubuntu repository

If you get prompted for confirmation, type Y and press Enter.

Once you install the .NET Core SDK, you will be able to issue dotnet commands without getting any errors.

shell
dotnet --version dotnet --help

run dotnet commands without getting errors

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.