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

本文详细描述了如何处理在使用MicrosoftAPT安装.NETCore时遇到的错误,包括移除所有现有.NET包、创建并编辑microsoft-dotnet.pref文件,以及选择使用Microsoft官方或Ubuntu仓库。
摘要由CSDN通过智能技术生成

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 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.

  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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值