答案1
时间过得很快,Ubuntu 上的软件包及其安装方法也随之变化。现在是 2023 年底,微软已停止对 .NET 5.0 的支持,因此您无法在微软的 Ubuntu 22.04 存储库中找到此版本的 .NET(如apt-cache
另一个答案中的命令)或使用官方安装网页中的任何说明。目前,如果您想安装 .NET 5.0,请按照以下命令操作:
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y dotnet-runtime-5.0
在第二个命令中,如果系统提示
==> Package distributor has shipped an updated version.
...
*** microsoft-prod.list (Y/I/N/O/D/Z) [default=N] ?
只需回答 Y 即可。
在最后一条命令中,你可能会得到:
The following packages have unmet dependencies:
dotnet-runtime-5.0 : Depends: dotnet-runtime-deps-5.0 (>= 5.0.17) but it is not going to be installed
Depends: dotnet-hostfxr-5.0 (>= 5.0.17) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
只要按照建议运行sudo apt --fix-broken install
,此命令将自动为您安装缺少的依赖包以及dotnet-runtime-5.0
。
我在 Ubuntu 22.04 上测试了上述命令。
答案2
sudo apt update
在尝试安装之前,您是否记得运行过?如果是这样,让我们确认该软件包是否在您的 Apt 缓存中可用:
打开终端(如果尚未打开)
检查
apt-cache
包裹dotnet-sdk
:$ sudo apt-cache dump | grep dotnet-sdk
你应该得到如下结果:
Package: dotnet-sdk-2.1 Package: dotnet-sdk-3.1 Package: dotnet-sdk-5.0
安装您想要的软件包:
$ sudo apt install dotnet-sdk-5.0
其结果应为:
Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: aspnetcore-runtime-5.0 aspnetcore-targeting-pack-5.0 dotnet-apphost-pack-5.0 dotnet-host dotnet-hostfxr-5.0 dotnet-runtime-5.0 dotnet-runtime-deps-5.0 dotnet-targeting-pack-5.0 netstandard-targeting-pack-2.1 The following NEW packages will be installed aspnetcore-runtime-5.0 aspnetcore-targeting-pack-5.0 dotnet-apphost-pack-5.0 dotnet-host dotnet-hostfxr-5.0 dotnet-runtime-5.0 dotnet-runtime-deps-5.0 dotnet-sdk-5.0 dotnet-targeting-pack-5.0 netstandard-targeting-pack-2.1 0 to upgrade, 10 to newly install, 0 to remove and 3 not to upgrade. Need to get 91.9 MB of archives. After this operation, 382 MB of additional disk space will be used. Do you want to continue? [Y/n]
希望这能帮助您确定为什么 apt 无法在您的系统上找到该包。