You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Xubuntu/Ubuntu 22.04中安装dotnet-sdk-7.0提示无安装候选且修复后影响.NET 6 SDK的问题求助

在Xubuntu/Ubuntu 22.04中安装dotnet-sdk-7.0提示无安装候选且修复后影响.NET 6 SDK的问题求助

各位大佬好,我最近在Ubuntu 22.04(Xubuntu桌面版)上折腾.NET SDK安装,遇到了一个头疼的问题,想请教下大家有没有解决方案。

情况是这样的:我先从Ubuntu官方源安装了.NET 6 SDK,之后想再装.NET 7 SDK,就按照步骤执行了以下命令:

wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update && sudo apt-get install dotnet-sdk-7.0

结果执行后直接报错,提示找不到安装候选:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package dotnet-sdk-7.0 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'dotnet-sdk-7.0' has no installation candidate

我有点纳闷,明明微软的源已经加上了,于是用sudo apt show dotnet-sdk-7.0 -a查看包信息,发现三个版本的.NET 7 SDK都在源里:

Package: dotnet-sdk-7.0
Version: 7.0.102-1
Priority: standard
Section: devel
Maintainer: Microsoft <dotnetcore@microsoft.com>
Installed-Size: 358 MB
Depends: aspnetcore-targeting-pack-7.0 (>= 7.0.2), netstandard-targeting-pack-2.1 (>= 2.1.0), dotnet-apphost-pack-7.0 (>= 7.0.2), dotnet-runtime-7.0 (>= 7.0.2), dotnet-targeting-pack-7.0 (>= 7.0.2), aspnetcore-runtime-7.0 (>= 7.0.2)
Homepage: https://github.com/dotnet/core
Download-Size: 90,6 MB
APT-Sources: https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 Packages
Description: Microsoft .NET SDK 7.0.102
.NET is a development platform that you can use to build command-line applications, microservices and modern websites. It is open source, cross-platform and is supported by Microsoft. We hope you enjoy using it! If you do, please consider joining the active community of developers that are contributing to the project on GitHub (https://github.com/dotnet/core). We happily accept issues and PRs.

Package: dotnet-sdk-7.0
Version: 7.0.101-1
Priority: standard
Section: devel
Maintainer: Microsoft <dotnetcore@microsoft.com>
Installed-Size: 358 MB
Depends: aspnetcore-targeting-pack-7.0 (>= 7.0.1), netstandard-targeting-pack-2.1 (>= 2.1.0), dotnet-apphost-pack-7.0 (>= 7.0.1), dotnet-runtime-7.0 (>= 7.0.1), dotnet-targeting-pack-7.0 (>= 7.0.1), aspnetcore-runtime-7.0 (>= 7.0.1)
Homepage: https://github.com/dotnet/core
Download-Size: 90,6 MB
APT-Sources: https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 Packages
Description: Microsoft .NET SDK 7.0.101
.NET is a development platform that you can use to build command-line applications, microservices and modern websites. It is open source, cross-platform and is supported by Microsoft. We hope you enjoy using it! If you do, please consider joining the active community of developers that are contributing to the project on GitHub (https://github.com/dotnet/core). We happily accept issues and PRs.

Package: dotnet-sdk-7.0
Version: 7.0.100-1
Priority: standard
Section: devel
Maintainer: Microsoft <dotnetcore@microsoft.com>
Installed-Size: 352 MB
Depends: aspnetcore-targeting-pack-7.0 (>= 7.0.0), netstandard-targeting-pack-2.1 (>= 2.1.0), dotnet-apphost-pack-7.0 (>= 7.0.0), dotnet-runtime-7.0 (>= 7.0.0), dotnet-targeting-pack-7.0 (>= 7.0.0), aspnetcore-runtime-7.0 (>= 7.0.0)
Homepage: https://github.com/dotnet/core
Download-Size: 88,4 MB
APT-Sources: https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 Packages
Description: Microsoft .NET SDK 7.0.100
.NET is a development platform that you can use to build command-line applications, microservices and modern websites. It is open source, cross-platform and is supported by Microsoft. We hope you enjoy using it! If you do, please consider joining the active community of developers that are contributing to the project on GitHub (https://github.com/dotnet/core). We happily accept issues and PRs.

我还试了sudo apt-get upgrade,但问题依旧。查看微软源的配置文件/etc/apt/sources.list.d/microsoft-prod.list,内容是正常的:

deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/22.04/prod jammy main

再用apt policy dotnet-sdk-7.0查看包优先级,发现这些包的优先级是-10,难怪apt不会选它们:

dotnet-sdk-7.0:
Installed: (none)
Candidate: (none)
Version table:
7.0.102-1 -10
500 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 Packages
7.0.101-1 -10
500 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 Packages
7.0.100-1 -10
500 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main amd64 Packages

后来我找到一个办法,创建了/etc/apt/preferences文件,内容如下:

Package: dotnet-sdk-7.0
Pin: origin "packages.microsoft.com"
Pin-Priority: 999

这样设置后,.NET 7 SDK确实能正常安装了,但新的问题出现了——之前安装的.NET 6 SDK不能用了!

现在想请教大家,有没有什么办法可以同时解决这两个问题:既让.NET 7 SDK能顺利安装,又不影响已有的.NET 6 SDK正常使用?

备注:内容来源于stack exchange,提问作者Alexander Zeitler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 16:03:14