Last updated: Apr 5, 2024
Reading time·3 min
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.
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.
# for ZSH (if you get an error) sudo apt remove 'dotnet*'
Make sure to type Y
and press Enter
if you get prompted for confirmation.
sudo apt remove netstandard* # for ZSH (if you get an error) sudo apt remove 'netstandard*'
sudo apt remove aspnetcore* # for ZSH (if you get an error) sudo apt remove 'aspnetcore*'
microsoft-dotnet.pref
file in your /etc/apt/preferences.d
directory.# using gedit sudo gedit /etc/apt/preferences.d/99microsoft-dotnet.pref
The command above uses gedit
, but you can also use nano
.
# using nano sudo nano /etc/apt/preferences.d/99microsoft-dotnet.pref
Or vim
.
# using Vim sudo vim /etc/apt/preferences.d/99microsoft-dotnet.pref
Add the following to your /etc/apt/preferences.d/99microsoft-dotnet.pref
file.
Package: * Pin: origin "packages.microsoft.com" Pin-Priority: 1001
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.
# 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.
Once you install the .NET Core SDK, you will be able to issue dotnet
commands
without getting any errors.
dotnet --version dotnet --help
The approach above uses the Microsoft .NET packages because they are regularly updated.
If you decide to use the Ubuntu packages, you have to delete the Microsoft repository.
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 .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
.
/etc/apt/preferences.d/99microsoft-dotnet.pref
file, delete it by running the following command.sudo rm -rf /etc/apt/preferences.d/99microsoft-dotnet.pref
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
# Download package information sudo apt update # Install the .NET Core SDK sudo apt install dotnet-sdk-6.0
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.
dotnet --version dotnet --help