PowerShell是由Microsoft开发的任务自动化和配置管理框架。它由命令行 shell、脚本语言和配置管理框架组成。PowerShell可在各种平台上使用,包括Windows,Linux和macOS。
在 Rocky Linux 9 上安装 PowerShell
第 1 步。第一步是将系统更新到最新版本的软件包列表。为此,请运行以下命令:
<span class="pln">sudo dnf check</span><span class="pun">-</span><span class="pln">update sudo dnf install dnf</span><span class="pun">-</span><span class="pln">utils sudo dnf install epel</span><span class="pun">-</span><span class="pln">release</span>
第 2 步。在 Rocky Linux 9 上安装 PowerShell。
默认情况下,PowerShell 在 Rocky Linux 9 基础存储库中不可用。现在运行以下命令,通过运行以下命令将 PowerShell 存储库添加到系统:
<span class="pln">sudo rpm </span><span class="pun">-</span><span class="typ">Uvh</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//packages.microsoft.com/config/rhel/9/prod.repo</span>
接下来,使用以下命令导入 GPG 密钥:
<span class="pln">sudo rpm </span><span class="pun">--</span><span class="kwd">import</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//packages.microsoft.com/keys/microsoft.asc</span>
添加存储库后,可以通过运行以下命令来安装 PowerShell:
<span class="pln">sudo yum install powershell</span>
第 3 步。在 Rocky Linux 9 上访问 PowerShell。
现在您已经登录到终端,以下是使用PowerShell的一些常见示例:
<span class="com"># </span><span class="ahmcommand"><span class="com">pwsh</span></span> <span class="typ">PowerShell</span> <span class="lit">7.2</span><span class="pun">.</span><span class="lit">4</span> <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">c</span><span class="pun">)</span> <span class="typ">Microsoft</span> <span class="typ">Corporation</span><span class="pun">.</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//aka.ms/powershell</span> <span class="typ">Type</span> <span class="str">'help'</span><span class="pln"> to </span><span class="kwd">get</span><span class="pln"> help</span><span class="pun">.</span><span class="pln"> PS </span><span class="pun">/</span><span class="pln">root</span><span class="pun">></span> <span class="ahmsetting"><span class="typ">Get</span><span class="pun">-</span><span class="typ">Date</span></span> <span class="typ">Monday</span><span class="pun">,</span> <span class="typ">Dec</span> <span class="lit">16</span><span class="pun">,</span> <span class="lit">2022</span> <span class="lit">7</span><span class="pun">:</span><span class="lit">46</span><span class="pun">:</span><span class="lit">11</span><span class="pln"> PM PS </span><span class="pun">/</span><span class="pln">root</span><span class="pun">></span> <span class="ahmsetting"><span class="typ">Get</span><span class="pun">-</span><span class="typ">PSDrive</span></span> <span class="typ">Name</span> <span class="typ">Used</span> <span class="pun">(</span><span class="pln">GB</span><span class="pun">)</span> <span class="typ">Free</span> <span class="pun">(</span><span class="pln">GB</span><span class="pun">)</span> <span class="typ">Provider</span> <span class="typ">Root</span> <span class="pun">----</span> <span class="pun">---------</span> <span class="pun">---------</span> <span class="pun">--------</span> <span class="pun">----</span> <span class="pun">/</span> <span class="lit">4.19</span> <span class="lit">80.73</span> <span class="typ">FileSystem</span> <span class="pun">/</span> <span class="typ">Alias</span> <span class="typ">Alias</span> <span class="typ">Env</span> <span class="typ">Environment</span> <span class="typ">Function</span> <span class="typ">Function</span> <span class="typ">Temp</span> <span class="lit">4.19</span> <span class="lit">80.73</span> <span class="typ">FileSystem</span> <span class="pun">/</span><span class="pln">tmp</span><span class="pun">/</span> <span class="typ">Variable</span> <span class="typ">Variable</span><span class="pln"> PS </span><span class="pun">/</span><span class="pln">root</span><span class="pun">></span> <span class="ahmsetting"><span class="kwd">exit</span></span>
感謝您使用這本教鬆在 Rocky Linux 9 系統上安裝 Microsoft PowerShell。有关其他帮助或有用信息,我们建议您查看 PowerShell 官方网站。