Debian 10 包管理器 - 安装 .NET CoreDebian 10 Package Manager - Install .NET Core

仅在 x64 体系结构上支持包管理器安装 。Package manager installs are only supported on the x64 architecture. 其他体系结构(如 ARM )必须手动安装 .NET Core SDK手动安装 .NET Core 运行时Other architectures, such as ARM, must manually install the .NET Core SDK or manually install the .NET Core Runtime. 有关详细信息,请参阅 .NET Core 依赖项和要求For more information, see .NET Core dependencies and requirements.

本文介绍如何使用包管理器在 Debian 10 上安装 .NET Core。This article describes how to use a package manager to install .NET Core on Debian 10. 如果要安装该运行时,建议安装 ASP.NET Core 运行时,因为它同时包括 .NET Core 和 ASP.NET Core 运行时。If you're installing the runtime, we suggest you install the ASP.NET Core runtime, as it includes both .NET Core and ASP.NET Core runtimes.

注册 Microsoft 密钥和源Register Microsoft key and feed

安装 .NET 之前,需要:Before installing .NET, you'll need to:

  • 注册 Microsoft 密钥。Register the Microsoft key.
  • 注册产品存储库。Register the product repository.
  • 安装必需的依赖项。Install required dependencies.

每台计算机只需要执行一次此操作。This only needs to be done once per machine.

打开终端并运行以下命令。Open a terminal and run the following commands.

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/debian/10/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list

安装 .NET Core SDKInstall the .NET Core SDK

更新可供安装的产品,然后安装 .NET Core SDK。Update the products available for installation, then install the .NET Core SDK. 在终端中,运行以下命令。In your terminal, run the following commands.

sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-3.1

安装 ASP.NET Core 运行时Install the ASP.NET Core runtime

更新可供安装的产品,然后安装 ASP.NET 运行时。Update the products available for installation, then install the ASP.NET runtime. 在终端中,运行以下命令。In your terminal, run the following commands.

sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install aspnetcore-runtime-3.1

安装 .NET Core 运行时Install the .NET Core runtime

更新可供安装的产品,然后安装 .NET Core 运行时。Update the products available for installation, then install the .NET Core runtime. 在终端中,运行以下命令。In your terminal, run the following commands.

sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-runtime-3.1

如何安装其他版本How to install other versions

添加到包管理器源的包以可改动的格式命名:{product}-{type}-{version}The packages added to the package manager feeds are named in a hackable format: {product}-{type}-{version}.

  • productproduct
    要安装的 .NET 产品的类型。The type of .NET product to install. 有效选项是:Valid options are:

    • dotnetdotnet
    • aspnetcoreaspnetcore
  • typetype
    选择 SDK 或运行时。Chooses the SDK or the runtime. 有效选项是:Valid options are:

    • SDKsdk
    • Runtime — 运行时runtime
  • versionversion
    要安装的 SDK 或运行时的版本。The version of the SDK or runtime to install. 本文始终提供最新支持的版本的说明。This article will always give the instructions for the latest supported version. 有效选项为任何已发布的版本,例如:Valid options are any released version, such as:

    • 3.03.0
    • 2.22.2
    • 2.12.1

示例Examples

  • 安装 .NET Core 2.2 SDK:dotnet-sdk-2.2Install the .NET Core 2.2 SDK: dotnet-sdk-2.2
  • 安装 ASP.NET Core 3.1 运行时:aspnetcore-runtime-3.1Install the ASP.NET Core 3.1 runtime: aspnetcore-runtime-3.1
  • 安装 .NET Core 2.1 运行时:dotnet-runtime-2.1Install the .NET Core 2.1 runtime: dotnet-runtime-2.1

缺少包Package missing

如果包版本组合无效,则它不可用。If the package-version combination doesn't work, it's not available. 例如,未安装 ASP.NET Core SDK,所有 SDK 组件都包含在 .NET Core SDK 中。For example, there isn't an ASP.NET Core SDK, the SDK components are included with the .NET Core SDK. aspnetcore-sdk-2.2 的值不正确,应为 dotnet-sdk-2.2The value aspnetcore-sdk-2.2 is incorrect and should be dotnet-sdk-2.2.

包管理器疑难解答Troubleshoot the package manager

本部分提供有关使用程序包管理器安装 .NET Core 时可能会遇到的常见错误的信息。This section provides information on common errors you may get while using the package manager to install .NET Core.

未能提取Failed to fetch

安装 .NET Core 包时,可能会看到类似于 Failed to fetch ... File has unexpected size ... Mirror sync in progress? 的错误。While installing the .NET Core package, you may see an error similar to Failed to fetch ... File has unexpected size ... Mirror sync in progress?. 一般而言,此错误表示 .NET Core 的包源正在通过更新的包版本进行更新,应稍后重试。Generally speaking, this error means that the package feed for .NET Core is being upgraded with newer package versions, and that you should try again later. 升级期间,包源的不可用时间不应超过 30 分钟。During an upgrade, the package feed should not be unavailable for more than 30 minutes. 如果持续收到此错误超过 30 分钟,请在 https://github.com/dotnet/core/issues 中提交问题。If you continually receive this error for more than 30 minutes, please file an issue at https://github.com/dotnet/core/issues.