在 Rocky Linux 8|AlmaLinux 8|RHEL 8 上安装 .NET Core 6.0

在本文中,我们将在 Rocky Linux 8|AlmaLinux 8|RHEL 8 上安装 .NET Core 6.0。.NET 是一个由编程语言、工具和库组成的开发人员平台,可帮助开发人员构建不同类型的应用程序。ASP.NET 框架通过工具和库扩展了 .NET 开发人员平台 ,使 Web 应用程序的构建变得顺畅和容易。在撰写本文时,.NET Core 的最新版本是 6.0,这是一个 LTS 版本。

.NET 6.0 LTS 版本可在 Windows、Linux 和 macOS 操作系统上下载。该软件包包括 .NET 运行时和 ASP.NET Core 运行时。IIS 用户有 ASP.NET Core 模块,可以在服务器上单独安装,无需安装 .NET Runtime。

以下发行版可用于 Linux:

  • .NET SDK:包括用于构建和测试应用程序的工具,并包括随后的运行时分发。
  • .NET 运行时:包括 .NET 运行时和库,支持运行控制台应用程序。
  • ASP.NET Core 运行时:包括 .NET 和 ASP.NET Core 运行时,支持运行控制台和 Web 应用程序。

在 Rocky Linux 8|AlmaLinux 8|RHEL 8 上安装 .NET Core 6.0

作为开发人员,您可以安装 .NET SDK 来开发和构建应用程序。测试应用程序后,需要其中一个运行时包(如 ASP.NET Core)来专门运行应用程序。

在 Rocky Linux 8|AlmaLinux 8|RHEL 8 上安装.NET SDK 6

包含的运行时是:

  • .NET 运行时
  • ASP.NET Core 运行时
  • .NET 桌面运行时

我们将使用 dotnet-install 脚本在我们的 Linux 系统上 自动安装 SDK 和 运行时。该脚本默认安装最新的 SDK 长期支持 (LTS),更新本文时为 6.0 LTS。

安装 wget 或 curl 下载器:

sudo dnf -y install wget curl

在本地下载.NET安装程序脚本:

# 两种下载方式,选其一即可
#Using curl
curl -sLO https://dot.net/v1/dotnet-install.sh

#Using wget
wget https://dot.net/v1/dotnet-install.sh

给脚本执行权限

chmod +x dotnet-install.sh

使用的脚本选项:

  • -c,–channel:从指定的频道下载,默认为LTS.

运行以下命令将安装.NET SDK 6.0

./dotnet-install.sh -c 6.0
dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.

dotnet-install: Downloading primary link https://dotnetcli.azureedge.net/dotnet/Sdk/6.0.101/dotnet-sdk-6.0.101-linux-x64.tar.gz
dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/6.0.101/dotnet-sdk-6.0.101-linux-x64.tar.gz
dotnet-install: Adding to current process PATH: `/home/rocky/.dotnet`. Note: This change will be visible only when sourcing script.
dotnet-install: Note that the script does not resolve dependencies during installation.
dotnet-install: To check the list of dependencies, go to https://docs.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.

要安装当前的 LTS 版本,请使用:

./dotnet-install.sh -c Current

要安装.NET Runtime而不是 SDK,请使用–runtime参数。

./dotnet-install.sh -c Current --runtime aspnetcore

将 .NET 二进制文件目录添加到您的 PATH

添加~/.dotnet/到您的 PATH 环境变量:

echo 'export PATH=$PATH:~/.dotnet/' | tee -a ~/.bashrc

使环境变量生效

source  ~/.bashrc

检查版本,确认有效

$ dotnet --version
6.0.101

为 .NET CLI 启用 TAB 键自动补全

通过在 shell 中键入 dotnet 命令,然后按 TAB 键来触发 .NET CLI 的 Tab 键自动补全。如下所示为您的 Shell 设置。

Bash,将以下代码添加到.bashrc文件中

# bash parameter completion for the dotnet CLI

_dotnet_bash_complete()
{
  local word=${COMP_WORDS[COMP_CWORD]}

  local completions
  completions="$(dotnet complete --position "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)"
  if [ $? -ne 0 ]; then
    completions=""
  fi

  COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}

complete -f -F _dotnet_bash_complete dotnet

Zsh,将以下代码添加到.zhsrc文件中

# zsh parameter completion for the dotnet CLI

_dotnet_zsh_complete()
{
  local completions=("$(dotnet complete "$words")")

  reply=( "${(ps:\n:)completions}" )
}

compctl -K _dotnet_zsh_complete dotnet

TAB键自动补全效果图:                

.NET 是一个跨平台的开发人员平台,旨在帮助您构建应用程序。.NET应用程序可以用 C#、F# 或 Visual Basic 编程语言编写。在本文中,我们已经能够在 Rocky Linux 8|AlmaLinux 8|RHEL 8 Linux 系统上安装 .NET Core 6.0。从这一点开始,您可以开始使用 .NET 为移动、Web、云、桌面、机器学习、游戏开发、物联网、微服务和许多其他平台构建应用程序。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值