INTRODUCTION:
So, I had spin up a new Ubuntu 22.04 server on AWS cloud, and choose to install dotnet 6 on it for my backend application that talks to a database. The whole installation went smoothly, however, when I typed in dotnet -v
to check if the application really installed, I was greeted with a funny looking set of error.
The error A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist
is a pretty interesting error that is unique to the Ubuntu 22.04 machine.
![usr/share/dotnet/host/fxr error for dotnet problems resolved](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/1-3.png?resize=647%2C46&ssl=1)
the Cause
The cause is when there is conflict on the choice of installed dotnet package manager inside the server. For Ubuntu and some other linux operating system, they have their own repository which also contain dotnet, while this was an okay development, Microsoft (the creator of dotnet) also developed their own repository for their packages, this includes the dontet too.
Therefore, both of the repositories with the dotnet package in the server conflicts, which resulted into A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist
.
the solution
Resolving this error is pretty easy, all you need to do is to specify one repository (any one of the repositories) to be the source of the dotnet package. We select only one because each repository have different directory path where the store their activities.
We will walk through how to select either Microsoft repositories or Ubuntu repositories shortly.
the steps
To resolve, lets follow the next few steps. We will start with the Microsoft repository option. If you prefer to use Ubuntu repository with is much easier to use, you can skip this step to the next.
to use microsoft repository
1. We need to uninstall the dotnet packages from the machine. Do not panic, we will reinstall them as we go in this walk through.
sudo apt remove dotnet*
![usr/share/dotnet/host/fxr error for dotnet problems resolved](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/2-3.png?resize=660%2C34&ssl=1)
sudo apt remove aspnetcore*
![usr/share/dotnet/host/fxr error for dotnet problems resolved oxla.io](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/3-3.png?resize=651%2C34&ssl=1)
sudo apt remove netstandard*
![usr/share/dotnet/host/fxr error for dotnet problems resolved oxla.io](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/4-3.png?resize=649%2C34&ssl=1)
2. The next step is to create and add the package.microsoft.com package origin to the pref file inside the preference.d directory.
sudo nano /etc/apt/preference.d/99microsoft-dotnet.pref
![usr/share/dotnet/host/fxr error for dotnet problems resolved oxla.io dotnet](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/5-4.png?resize=662%2C35&ssl=1)
Paste the code snippet below in the filepackage: *
Pin: origin "package.microsoft.com"
Pin-Priority: 1001
![microsoft package repository](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/6-3.png?resize=654%2C128&ssl=1)
Once that is done, we need to update the apt repository on the machine to reflect our changes.
sudo apt update
![oxla.io apt update](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/7-1.png?resize=669%2C32&ssl=1)
Cool, now let’s reinstall the dotnet that we uninstall earlier. You can install any of the dotnet that works for your application, however, I installed the 6.0 SDK version, because that is what my application requires.
sudo apt install dotnet-sdk-6.0
![oxla.io blog](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/8.png?resize=660%2C36&ssl=1)
After the installation is done, you can confirm that dotnet is installed properly by checking the version.
dotnet --version
![version check oxla.io blog](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/9.png?resize=657%2C46&ssl=1)
to use the ubuntu repository
Also, if you choose to use the Ubuntu repository, you can do that is 3 steps.
First, remove the microsoft-prod.list file from the Ubuntu source list in apt directory
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
![](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/10.png?resize=738%2C23&ssl=1)
Then you can go ahead to update the apt repository.
sudo apt update
![](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/11.png?resize=563%2C29&ssl=1)
Then install the dotnet you prefer to install. And, lastly, check the version using the dotnet -v
command.
sudo apt install dotnet-sdk-6.0
![](https://i0.wp.com/oxla.io/wp-content/uploads/2023/03/12.png?resize=665%2C33&ssl=1)
CONCLUSION
Now you have no worry when next you find this error. I recommend you bookmark this page for future reference.
Leave a Reply