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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

<think>好的,我现在需要解决用户遇到的Dotnet运行时错误:“A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist”。这个问题通常是由于不同来源的.NET安装冲突或路径配置错误引起的。根据用户提供的引用信息,我需要结合已有的解决方案,整理出可行的步骤。 首先,根据引用[1],问题可能来源于同时安装了Microsoft APT源和Ubuntu仓库的.NET版本,导致路径冲突。所以第一步应该是清理现有的所有安装,确保系统处于干净状态。引用[3]提到在Ubuntu 20.04中需要先删除所有相关包,所以用户应该运行类似`sudo apt remove dotnet* aspnetcore* netstandard*`的命令。不过要注意,用户可能是在CentOS或其他系统,所以可能需要调整命令,比如使用`yum remove`。 接下来,重新安装.NET。根据引用[1]和[2],安装时应该选择单一来源,避免混合安装。例如,如果用户使用Microsoft的APT源,那么应该确保只从该源安装,而不是同时使用Ubuntu的仓库。安装完成后,可能需要手动设置环境变量,如引用[2]中的例子,设置`DOTNET_ROOT`和`PATH`,确保指向正确的安装路径。这里需要注意用户的安装路径是否正确,比如检查`/usr/share/dotnet`是否存在,或者是否安装到了用户目录下,如`$HOME/.dotnet`。 另外,权限问题也可能导致路径无法访问。如果安装后的目录权限不正确,用户可能需要使用`chmod`或`chown`调整权限。例如,`/usr/share/dotnet`可能需要适当的读写权限给当前用户。 还有符号链接的问题,如引用[2]提到的,如果安装路径不在默认路径下,可能需要创建符号链接到系统路径。例如,将用户目录下的dotnet链接到`/usr/local/bin`,这样系统可以正确找到命令。 最后,验证安装是否成功,使用`dotnet --info`查看信息,确保没有错误,并且显示的版本与安装的一致。如果仍有问题,可能需要检查环境变量是否正确加载,或者是否有残留文件未清理干净。 总结步骤应该是:清理旧安装→重新安装正确的版本→配置环境变量→处理权限或符号链接→验证。同时需要区分不同操作系统(如Ubuntu和CentOS)的具体命令差异,确保用户根据自身系统选择合适的解决方案。</think>### 解决步骤 #### 1. 清理冲突安装(关键步骤) 首先删除所有残留的旧版或冲突的.NET安装: - **Ubuntu/Debian**: ```bash sudo apt remove dotnet* aspnetcore* netstandard* sudo rm -rf /usr/share/dotnet # 手动删除残留目录 ``` - **CentOS/RHEL**: ```bash sudo yum remove dotnet* aspnetcore* netstandard* sudo rm -rf /usr/share/dotnet ``` 此步骤避免多个来源的安装冲突[^1][^3]。 #### 2. 重新安装.NET Core 选择**单一安装来源**,推荐使用Microsoft官方渠道: - **Ubuntu/Debian**(通过APT): ```bash wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo apt update sudo apt install dotnet-sdk-6.0 # 替换为所需版本 ``` - **CentOS**(通过RPM): ```bash sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm sudo yum install dotnet-sdk-6.0 ``` #### 3. 配置环境变量 若安装路径不在默认位置(如用户目录),需手动设置环境变量: ```bash # 添加到 ~/.bashrc 或 ~/.zshrc export DOTNET_ROOT=/usr/share/dotnet # 根据实际安装路径调整 export PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools" ``` 执行 `source ~/.bashrc` 后验证: ```bash echo $DOTNET_ROOT # 应输出正确路径 ``` #### 4. 修复路径与权限 - **检查安装路径是否存在**: ```bash ls -l /usr/share/dotnet # 确认目录结构包含host/fxr ``` 若目录缺失,重新安装SDK或运行时。 - **修复权限问题**: ```bash sudo chmod -R 755 /usr/share/dotnet sudo chown -R root:root /usr/share/dotnet ``` #### 5. 验证安装 ```bash dotnet --info # 正确输出应包含SDK版本和运行时路径 ``` ### 常见问题补充 1. **安装后仍提示路径错误** 检查符号链接是否有效: ```bash which dotnet # 应指向/usr/share/dotnet/dotnet # 若无效,手动创建链接 sudo ln -s /usr/share/dotnet/dotnet /usr/local/bin/dotnet ``` 2. **混合安装导致冲突** 确保仅保留**一个来源**的.NET安装(如仅用Microsoft包或仅用发行版仓库)。 ### 引用 [^1]: 安装冲突导致路径错误 [^2]: 环境变量配置方法 [^3]: 清理残留包操作
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值