本文内容
GitHub版本页面上提供有所有可用包。安装包之后,从终端运行pwsh。若已安装预览版,请运行pwsh-preview。
还有三种在Linux发行版中安装PowerShell的其他方式:
Snap包
Snap是便于安装、安全、跨平台和无依赖项的应用程序包。可以从SnapStore中发觉和安装Snap。Snap包与正在运行此包的发行版遭到相同的支持。
重要
SnapStore包含许多针对Microsoft未即将支持的Linux发行版的PowerShellSnap包。有关支持,请参阅可用的社区支持选项列表。
获取snapd
需具备snapd能够运行Snap。根据这种说明确保你已安装snapd。
通过Snap进行安装
为简化安装和更新,已向Snap储存发布适用于Linux的PowerShell。
首选方式如下所示:
# Install PowerShell
sudo snap install powershell --classic
# Start PowerShell
pwsh
若要安装最新的LTS版本,请使用以下方式:
# Install PowerShell
sudo snap install powershell --channel=lts/stable --classic
# Start PowerShell
pwsh
若要安装预览版本打印linux发行版本程序,请使用以下方式:
# Install PowerShell
sudo snap install powershell-preview --classic
# Start PowerShell
pwsh-preview
安装完成后,Snap将手动升级。可以使用sudosnaprefreshpowershell或sudosnaprefreshpowershell-preview触发升级。
卸载
sudo snap remove powershell
或
sudo snap remove powershell-preview
二补码存档
已对Linux平台提供PowerShell二补码tar.gz存档,以启用中级布署方案。
备注
你可以使用此方式安装任何版本的PowerShell,包括最新版本:
依赖项
PowerShell为所有Linux分发版生成可移植二补码文件。并且对于不同的分发版打印linux发行版本程序,.NETCore运行时须要不同的依赖项,但是PowerShell也有相同要求。
安装PowerShell时,比如通过二补码存档自动安装时linux软件,可能不会安装特定依赖项。下边的列表详尽列举了Microsoft支持的Linux发行版以及可能须要安装的依赖项。更多信息,请查看发行版页面:
若要在不受即将支持的Linux分发版上布署PowerShell二补码文件,则需在各个步骤中安装目标OS的必要依赖项。诸如,AmazonLinuxdockerfile先安装依赖项linux怎么查看系统版本,之后提取Linuxtar.gz存档。
使用二补码存档文件进行安装
重要
此方式可用于在任何Linux版本(包括Microsoft未即将支持的发行版)上安装PowerShell。请勿必安装任何须要的依赖项。有关支持,请参阅可用的社区支持选项列表。
下边的示例展示了安装x64二补码存档的步骤。必须选择与平台的处理器类型匹配的正确二补码存档。
使用以下shell命令从tar.gz二补码存档下载并安装PowerShell。修改URL以匹配要安装的PowerShell版本。
# Download the powershell '.tar.gz' archive
curl -L -o /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.3.11/powershell-7.3.11-linux-x64.tar.gz
# Create the target folder where powershell will be placed
sudo mkdir -p /opt/microsoft/powershell/7
# Expand powershell to the target folder
sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7
# Set execute permissions
sudo chmod +x /opt/microsoft/powershell/7/pwsh
# Create the symbolic link that points to pwsh
sudo ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh
卸载二补码存档
sudo rm -rf /usr/bin/pwsh /opt/microsoft/powershell
作为.NET全局工具安装
假如你已安装.NETCoreSDK,则可以轻松地安装PowerShell作为.NET全局工具。
dotnet tool install --global PowerShell
dotnet工具安装程序将~/.dotnet/tools添加到PATH环境变量中。并且,当前运行的shell没有更新的PATH。应当可以通过键入pwsh从新shell启动PowerShell。