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.
- 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*'
Make sure to type Y
and press Enter
if you get prompted for confirmation.
- 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*'
- 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*'
- 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
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.
Once you install the .NET Core SDK, you will be able to issue dotnet
commands without getting any errors.
shell
dotnet --version dotnet --help
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:
- Remove all .NET packages from your machine.
shell
# 1) remove .NET packages sudo apt remove 'dotnet*' # 2) remove .NET standard packags 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
.
- 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 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
- Install the .NET Core SDK.
shell
# 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.
shell
dotnet --version dotnet --help
I wrote a book in which I share everything I know about how to become a better, more efficient programmer.