在本教程中,我们将向您展示如何在 AlmaLinux 8 上安装 Powershell。 对于那些不知道的人,PowerShell Core 是一个运行良好的跨平台(Windows、Linux 和 macOS)自动化和配置工具/框架使用您现有的工具,并针对处理结构化数据(例如 JSON、CSV、XML 等)、REST API 和对象模型进行了优化。 它包括一个命令行外壳、一个相关的脚本语言和一个用于处理 cmdlet 的框架。
本文假设您至少具有 Linux 的基本知识,知道如何使用 shell,最重要的是,您将站点托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户中运行,否则您可能需要添加 ‘sudo
‘ 获取 root 权限的命令。 我将向您展示在 AlmaLinux 8 上逐步安装 Powershell。您可以按照 Rocky Linux 的相同说明进行操作。
在 AlmaLinux 8 上安装 Powershell
步骤 1. 首先,让我们先确保您的系统是最新的。
sudo dnf update sudo dnf install epel-release
步骤 2. 在 AlmaLinux 8 上安装 Snap。
现在我们运行以下命令将 Snap 安装到您的系统:
sudo dnf install snapd
安装完成后,我们需要启用并启动 Snapd 守护进程:
sudo systemctl enable --now snapd.socket sudo systemctl start --now snapd.socket
要启用经典快照支持,请输入以下内容以在它们之间创建符号链接 /var/lib/snapd/snap
和 /snap
:
sudo ln -s /var/lib/snapd/snap /snap
步骤 2. 在 AlmaLinux 8 上安装 PowerShell。
- 使用 Snap 安装 PowerShell。
使用 snap 安装 PowerShell 的最简单方法如下:
sudo snap install powershell --classic
- 从 GitHub 安装 PowerShell。
大多数 Linux 发行版现在正式支持 PowerShell。 所有最新的 PowerShell Linux 软件包都可以在 GitHub:
sudo dnf install https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/powershell-7.1.4-1.centos.8.x86_64.rpm
成功安装后,这是PowerShell的基本用法:
[email protected] ~]# pwsh
PowerShell 7.1.4 Copyright (c) Microsoft Corporation. All rights reserved. https://aka.ms/powershell Type 'help' to get help. PS /root># display Cmdlet list (only display 8 lines from the head) PS /root> (Get-Command)[0..9] CommandType Name Version Source ----------- ---- ------- ------ Function cd.. Function cd Function Clear-Host Function Compress-Archive 1.2.6 Microsoft.PowerShell.Archive Function Configuration 2.0.6 PSDesiredStateConfiguration Function Expand-Archive 1.2.8 Microsoft.PowerShell.Archive Function Find-Command 2.2.5.4 PowerShellGet Function Find-DSCResource 2.2.5.4 PowerShellGet Function Find-Module 2.2.5.4 PowerShellGet Function Find-RoleCapability 2.2.5.4 PowerShellGet
恭喜! 您已成功安装 Powershell。 感谢您使用本教程在您的 AlmaLinux 8 系统上安装 Powershell。 如需更多帮助或有用信息,我们建议您查看 Powershell 官方网站.