当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 Rocky Linux 8|AlmaLinux 8|RHEL 8 上安装 .NET Core 6.0

作者:精品下载站 日期:2024-12-14 12:22:54 浏览:11 分类:玩电脑

在 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.
dotnet-install: Installation finished successfully.

要安装当前的 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
$ echo $PATH
$ echo $PATH
/home/rocky/.local/bin:/home/rocky/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/rocky/.dotnet/

尝试运行 dotnet 命令来检查版本:

$ dotnet --version
6.0.101

创建 hello world 测试

$ dotnet new console -o helloworld

Welcome to .NET 6.0!
---------------------
SDK Version: 6.0.101

Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
Learn about HTTPS: https://aka.ms/dotnet-https
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
The template "Console App" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /home/rocky/helloworld/helloworld.csproj...
  Determining projects to restore...
  Restored /home/rocky/helloworld/helloworld.csproj (in 97 ms).
Restore succeeded.

运行应用程序

$ cd helloworld
$ dotnet run
Hello, World!

为 .NET CLI 启用 TAB 自动补全

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

重击

要向 .NET CLI 的 bash shell 添加制表符补全功能,请将以下代码添加到您的 .bashrc 文件中:

$ vim ~/.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

兹什

要向 .NET CLI 的 zsh shell 添加 Tab 键补全功能,请将以下代码添加到您的 .zshrc 文件中:

$ vim ~/.zshrc
# 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 补全用法示例:

[玩转系统] 在 Rocky Linux 8|AlmaLinux 8|RHEL 8 上安装 .NET Core 6.0

结论

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

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯