在 Linux 上安装 PowerShellInstalling PowerShell on Linux

GitHub 版本页面上提供有所有可用包。All packages are available on our GitHub releases page. 安装包以后,从终端运行 pwshAfter the package is installed, run pwsh from a terminal. 若已安装 预览版,请运行 pwsh-previewRun pwsh-preview if you installed a Preview release.

备注

PowerShell 7 是就地升级,升级后会删除 PowerShell Core 6.x。PowerShell 7 is an in-place upgrade that removes PowerShell Core 6.x.

/usr/local/microsoft/powershell/6 文件夹被替换为 /usr/local/microsoft/powershell/7The /usr/local/microsoft/powershell/6 folder is replaced by /usr/local/microsoft/powershell/7.

如果需要与 PowerShell 7 并行运行 PowerShell 6,请使用二进制存档方法重新安装 PowerShell 6。If you need to run PowerShell 6 side-by-side with PowerShell 7, reinstall PowerShell 6 using the binary archive method.

对于未获得官方支持的 Linux 分发,可尝试使用 PowerShell Snap 包安装 PowerShell。For Linux distributions that aren't officially supported, you can try to install PowerShell using the PowerShell Snap Package. 还可尝试直接使用 Linux tar.gz存档 部署 PowerShell 二进制文件,但是需要在各个步骤中基于 OS 设置必要的依赖项。You can also try deploying PowerShell binaries directly using the Linux tar.gz archive, but you would need to set up the necessary dependencies based on the OS in separate steps.

官方支持的版本Officially supported releases

  • Ubuntu 16.04Ubuntu 16.04
  • Ubuntu 18.04Ubuntu 18.04
  • Debian 8Debian 8
  • Debian 9Debian 9
  • Debian 10Debian 10
  • Alpine 3.9 和 Alpine 3.10Alpine 3.9 and 3.10
  • CentOS 7CentOS 7
  • Red Hat Enterprise Linux (RHEL) 7Red Hat Enterprise Linux (RHEL) 7
  • Fedora 28Fedora 28
  • Fedora 29Fedora 29
  • Fedora 30Fedora 30
  • openSUSE 42.3openSUSE 42.3
  • openSUSE Leap 15openSUSE Leap 15

社区支持的版本Community supported releases

  • Ubuntu 18.10Ubuntu 18.10
  • Ubuntu 19.04Ubuntu 19.04
  • Arch LinuxArch Linux
  • KaliKali
  • Raspbian(试验版)Raspbian (experimental)

备选安装方法Alternate install methods

  • Snap 包Snap Package
  • 二进制存档Binary Archives
  • .NET 全局工具.NET Global tool

目前不支持Not currently supported

  • Ubuntu 20.04Ubuntu 20.04

备注

PowerShell 仅支持 .NET 支持的发行版。PowerShell can only support the distributions that are supported by .NET. 有关支持的发行版列表,请参阅 .NET Core 发行说明See the .NET Core release notes for a list of supported distributions. 如果有未在此处列出的 .NET 支持的发行版,可以请求添加对该发行版的支持。If there is a distrbution supported by .NET that is not listed here, you can request that support for the distribution be added. 请使用发行版支持请求模板来提交请求。Please file a request using the Distribution Support Request template.

Ubuntu 16.04Ubuntu 16.04

通过包存储库安装 - Ubuntu 16.04Installation via Package Repository - Ubuntu 16.04

为简化安装和更新,已将适用于 Linux 的 PowerShell 发布到包存储库。PowerShell for Linux is published to package repositories for easy installation and updates.

首选方法如下所示:The preferred method is as follows:

# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh

以超级用户身份注册 Microsoft 存储库一次。As superuser, register the Microsoft repository once. 注册后,可以通过 sudo apt-get install powershell 更新 PowerShell。After registration, you can update PowerShell with sudo apt-get install powershell.

通过直接下载进行安装 - Ubuntu 16.04Installation via Direct Download - Ubuntu 16.04

版本页中将 Debian 包 powershell-lts_7.0.3-1.ubuntu.16.04_amd64.deb 下载到 Ubuntu 计算机。Download the Debian package powershell-lts_7.0.3-1.ubuntu.16.04_amd64.deb from the releases page onto the Ubuntu machine.

然后在终端中执行以下命令:Then, in the terminal, execute the following commands:

sudo dpkg -i powershell-lts_7.0.3-1.ubuntu.16.04_amd64.deb
sudo apt-get install -f

备注

dpkg -i 命令失败,未满足依赖项。The dpkg -i command fails with unmet dependencies. 下一命令 apt-get install -f 解决此类问题,然后完成 PowerShell 包配置。The next command, apt-get install -f resolves these issues then finishes configuring the PowerShell package.

卸载 - Ubuntu 16.04Uninstallation - Ubuntu 16.04

sudo apt-get remove powershell

Ubuntu 18.04Ubuntu 18.04

通过包存储库安装 - Ubuntu 18.04Installation via Package Repository - Ubuntu 18.04

为简化安装和更新,已将适用于 Linux 的 PowerShell 发布到包存储库。PowerShell for Linux is published to package repositories for easy installation and updates.

首选方法如下所示:The preferred method is as follows:

# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Enable the "universe" repositories
sudo add-apt-repository universe

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh

以超级用户身份注册 Microsoft 存储库一次。As superuser, register the Microsoft repository once. 注册后,可以通过 sudo apt-get install powershell 更新 PowerShell。After registration, you can update PowerShell with sudo apt-get install powershell.

通过直接下载安装 - Ubuntu 18.04Installation via Direct Download - Ubuntu 18.04

版本页中将 Debian 包 powershell-lts_7.0.3-1.ubuntu.18.04_amd64.deb 下载到 Ubuntu 计算机。Download the Debian package powershell-lts_7.0.3-1.ubuntu.18.04_amd64.deb from the releases page onto the Ubuntu machine.

然后在终端中执行以下命令:Then, in the terminal, execute the following commands:

sudo dpkg -i powershell-lts_7.0.3-1.ubuntu.18.04_amd64.deb
sudo apt-get install -f

备注

dpkg -i 命令失败,未满足依赖项。The dpkg -i command fails with unmet dependencies. 下一命令 apt-get install -f 解决此类问题,然后完成 PowerShell 包配置。The next command, apt-get install -f resolves these issues then finishes configuring the PowerShell package.

卸载 - Ubuntu 18.04Uninstallation - Ubuntu 18.04

sudo apt-get remove powershell

Ubuntu 18.10Ubuntu 18.10

安装是通过 snapd 受到支持。Installation is supported via snapd. 有关说明,请参阅 Snap 包For instructions, see Snap Package.

备注

Ubuntu 18.10 是支持社区过渡版本Ubuntu 18.10 is an interim release that's community supported.

Ubuntu 19.04Ubuntu 19.04

安装是通过 snapd 受到支持。Installation is supported via snapd. 有关说明,请参阅 Snap 包For instructions, see Snap Package.

备注

Ubuntu 19.04 是社区支持过渡版本Ubuntu 19.04 is an interim release that's community supported.

Ubuntu 20.04Ubuntu 20.04

Ubuntu 20.04 是一个 LTS 版本。Ubuntu 20.04 is an LTS release. PowerShell 当前不支持此版本。PowerShell does not currently support this version. 正在考虑在 PowerShell 7.1 中添加对此版本此支持。Support for this version is being considered for the PowerShell 7.1 release. 如果希望支持 Ubuntu 20.04,请投票支持此请求Please upvote this request if you would like support for Ubuntu 20.04.

Debian 8Debian 8

通过包存储库安装 - Debian 8Installation via Package Repository - Debian 8

为简化安装和更新,已将适用于 Linux 的 PowerShell 发布到包存储库。PowerShell for Linux is published to package repositories for easy installation and updates.

首选方法如下所示:The preferred method is as follows:

# Install system components
sudo apt-get update
sudo apt-get install -y curl apt-transport-https

# Import the public repository GPG keys
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

# Register the Microsoft Product feed
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-jessie-prod jessie main" > /etc/apt/sources.list.d/microsoft.list'

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh

以超级用户身份注册 Microsoft 存储库一次。As superuser, register the Microsoft repository once. 注册后,可以通过 sudo apt-get install powershell 更新 PowerShell。After registration, you can update PowerShell with sudo apt-get install powershell.

Debian 9Debian 9

通过包存储库安装 - Debian 9Installation via Package Repository - Debian 9

为简化安装和更新,已将适用于 Linux 的 PowerShell 发布到包存储库。PowerShell for Linux is published to package repositories for easy installation and updates.

首选方法如下所示:The preferred method is as follows:

# Install system components
sudo apt-get update
sudo apt-get install -y curl gnupg apt-transport-https

# Import the public repository GPG keys
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

# Register the Microsoft Product feed
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list'

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh

以超级用户身份注册 Microsoft 存储库一次。As superuser, register the Microsoft repository once. 注册后,可以通过 sudo apt-get install powershell 更新 PowerShell。After registration, you can update PowerShell with sudo apt-get install powershell.

通过直接下载进行安装 - Debian 9Installation via Direct Download - Debian 9

版本页中将 Debian 包 powershell-lts_7.0.3-1.debian.9_amd64.deb 下载到 Debian 计算机。Download the Debian package powershell-lts_7.0.3-1.debian.9_amd64.deb from the releases page onto the Debian machine.

然后在终端中执行以下命令:Then, in the terminal, execute the following commands:

sudo dpkg -i powershell-lts_7.0.3-1.debian.9_amd64.deb
sudo apt-get install -f

卸载 - Debian 9Uninstallation - Debian 9

sudo apt-get remove powershell

Debian 10Debian 10

备注

Debian 10 仅在 PowerShell 7.0 以及更新版本中受到支持。Debian 10 is only supported in PowerShell 7.0 and newer.

通过包存储库安装 - Debian 10Installation via Package Repository - Debian 10

为简化安装和更新,已将适用于 Linux 的 PowerShell 发布到包存储库。PowerShell for Linux is published to package repositories for easy installation and updates.

首选方法如下所示:The preferred method is as follows:

# Download the Microsoft repository GPG keys
wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh

通过直接下载进行安装 - Debian 10Installation via Direct Download - Debian 10

版本页中将 tar.gz 包 powershell-7.0.3-linux-x64.tar.gz 下载到 Debian 计算机。Download the tar.gz package powershell-7.0.3-linux-x64.tar.gz from the releases page onto the Debian machine.

然后在终端中执行以下命令:Then, in the terminal, execute the following commands:

sudo apt-get update
# install the requirements
sudo apt-get install -y \
        less \
        locales \
        ca-certificates \
        libicu63 \
        libssl1.1 \
        libc6 \
        libgcc1 \
        libgssapi-krb5-2 \
        liblttng-ust0 \
        libstdc++6 \
        zlib1g \
        curl

# Download the powershell '.tar.gz' archive
curl -L  https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-7.0.3-linux-x64.tar.gz -o /tmp/powershell.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

# Start PowerShell
pwsh

Alpine 3.9 和 Alpine 3.10Alpine 3.9 and 3.10

备注

Alpine 3.9 和 Alpine 3.10 仅在 PowerShell 7.0 以及更新版本中受到支持。Alpine 3.9 and 3.10 are only supported in PowerShell 7.0 and newer.

通过直接下载进行安装 - Alpine 3.9 和 3.10Installation via Direct Download - Alpine 3.9 and 3.10

版本页中将 tar.gz 包 powershell-7.0.3-linux-alpine-x64.tar.gz 下载到 Alpine 计算机。Download the tar.gz package powershell-7.0.3-linux-alpine-x64.tar.gz from the releases page onto the Alpine machine.

然后在终端中执行以下命令:Then, in the terminal, execute the following commands:

# install the requirements
sudo apk add --no-cache \
    ca-certificates \
    less \
    ncurses-terminfo-base \
    krb5-libs \
    libgcc \
    libintl \
    libssl1.1 \
    libstdc++ \
    tzdata \
    userspace-rcu \
    zlib \
    icu-libs \
    curl

sudo apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \
    lttng-ust

# Download the powershell '.tar.gz' archive
curl -L https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-7.0.3-linux-alpine-x64.tar.gz -o /tmp/powershell.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

# Start PowerShell
pwsh

CentOS 7CentOS 7

备注

此包可以在 Oracle Linux 7 上运行。This package works on Oracle Linux 7.

通过包存储库安装(首选)- CentOS 7Installation via Package Repository (preferred) - CentOS 7

为简化安装和更新,已将适用于 Linux 的 PowerShell 发布到正式的 Microsoft 存储库。PowerShell for Linux is published to official Microsoft repositories for easy installation and updates.

# Register the Microsoft RedHat repository
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

# Install PowerShell
sudo yum install -y powershell

# Start PowerShell
pwsh

以超级用户身份注册 Microsoft 存储库一次。As superuser, register the Microsoft repository once. 注册后,可以通过 sudo yum update powershell 更新 PowerShell。After registration, you can update PowerShell with sudo yum update powershell.

通过直接下载进行安装 - CentOS 7Installation via Direct Download - CentOS 7

使用 CentOS 7时,请从版本页中将 RPM 包 powershell-lts-7.0.3-1.rhel.7.x86_64.rpm 下载到 CentOS 计算机。Using CentOS 7, download the RPM package powershell-lts-7.0.3-1.rhel.7.x86_64.rpm from the releases page onto the CentOS machine.

然后在终端中执行以下命令:Then, in the terminal, execute the following commands:

sudo yum install powershell-lts-7.0.3-1.rhel.7.x86_64.rpm

无需该中间下载步骤即可安装 RPM:You can install the RPM without the intermediate step of downloading it:

sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-lts-7.0.3-1.rhel.7.x86_64.rpm

卸载 - CentOS 7Uninstallation - CentOS 7

sudo yum remove powershell

Red Hat Enterprise Linux (RHEL) 7Red Hat Enterprise Linux (RHEL) 7

通过包存储库安装(首选)- Red Hat Enterprise Linux (RHEL) 7Installation via Package Repository (preferred) - Red Hat Enterprise Linux (RHEL) 7

为简化安装和更新,已将适用于 Linux 的 PowerShell 发布到正式的 Microsoft 存储库。PowerShell for Linux is published to official Microsoft repositories for easy installation and updates.

# Register the Microsoft RedHat repository
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

# Install PowerShell
sudo yum install -y powershell

# Start PowerShell
pwsh

以超级用户身份注册 Microsoft 存储库一次。As superuser, register the Microsoft repository once. 注册后,可以通过 sudo yum update powershell 更新 PowerShell。After registration, you can update PowerShell with sudo yum update powershell.

通过直接下载进行安装 - Red Hat Enterprise Linux (RHEL) 7Installation via Direct Download - Red Hat Enterprise Linux (RHEL) 7

版本页中将 RPM 包 powershell-lts-7.0.3-1.rhel.7.x86_64.rpm 下载到 Red Hat Enterprise Linux 计算机。Download the RPM package powershell-lts-7.0.3-1.rhel.7.x86_64.rpm from the releases page onto the Red Hat Enterprise Linux machine.

然后在终端中执行以下命令:Then, in the terminal, execute the following commands:

sudo yum install powershell-lts-7.0.3-1.rhel.7.x86_64.rpm

无需该中间下载步骤即可安装 RPM:You can install the RPM without the intermediate step of downloading it:

sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-lts-7.0.3-1.rhel.7.x86_64.rpm

卸载 - Red Hat Enterprise Linux (RHEL) 7Uninstallation - Red Hat Enterprise Linux (RHEL) 7

sudo yum remove powershell

OpenSUSEopenSUSE

安装 - openSUSE 42.3Installation - openSUSE 42.3

# Install dependencies
zypper update && zypper --non-interactive install curl tar libicu52_1

# Download the powershell '.tar.gz' archive
curl -L https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-7.0.3-linux-x64.tar.gz -o /tmp/powershell.tar.gz

# Create the target folder where powershell will be placed
mkdir -p /opt/microsoft/powershell/7

# Expand powershell to the target folder
tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7

# Set execute permissions
chmod +x /opt/microsoft/powershell/7/pwsh

# Create the symbolic link that points to pwsh
ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh

# Start PowerShell
pwsh

安装 - openSUSE Leap 15Installation - openSUSE Leap 15

# Install dependencies
zypper update && zypper --non-interactive install curl tar gzip libopenssl1_0_0 libicu60_2

# Download the powershell '.tar.gz' archive
curl -L https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-7.0.3-linux-x64.tar.gz -o /tmp/powershell.tar.gz

# Create the target folder where powershell will be placed
mkdir -p /opt/microsoft/powershell/7

# Expand powershell to the target folder
tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7

# Set execute permissions
chmod +x /opt/microsoft/powershell/7/pwsh

# Create the symbolic link that points to pwsh
ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh

# Start PowerShell
pwsh

卸载 - OpenSUSE 42.3、openSUSE Leap 15Uninstallation - openSUSE 42.3, openSUSE Leap 15

rm -rf /usr/bin/pwsh /opt/microsoft/powershell

FedoraFedora

备注

Fedora 28 仅在 PowerShell 6.1 以及更新版本中受到支持。Fedora 28 is only supported in PowerShell 6.1 and newer.

备注

Fedora 29 和 Fedora 30 仅在 PowerShell 7.0 以及更新版本中受到支持。Fedora 29 and 30 are only supported in PowerShell 7.0 and newer.

通过包存储库安装(首选)- Fedora 28、Fedora 29 和 Fedora 30Installation via Package Repository (preferred) - Fedora 28, 29, and 30

为简化安装和更新,已将适用于 Linux 的 PowerShell 发布到正式的 Microsoft 存储库。PowerShell for Linux is published to official Microsoft repositories for easy installation and updates.

# Register the Microsoft signature key
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

# Register the Microsoft RedHat repository
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

# Update the list of products
sudo dnf check-update

# Install a system component
sudo dnf install compat-openssl10

# Install PowerShell
sudo dnf install -y powershell

# Start PowerShell
pwsh

通过直接下载进行安装 - Fedora 28、Fedora 29 和 Fedora 30Installation via Direct Download - Fedora 28, 29, and 30

版本页中将 RPM 包 powershell-7.0.3-1.rhel.7.x86_64.rpm 下载到 Fedora 计算机。Download the RPM package powershell-7.0.3-1.rhel.7.x86_64.rpm from the releases page onto the Fedora machine.

然后在终端中执行以下命令:Then, in the terminal, execute the following commands:

sudo dnf install compat-openssl10
sudo dnf install powershell-7.0.3-1.rhel.7.x86_64.rpm

无需该中间下载步骤即可安装 RPM:You can install the RPM without the intermediate step of downloading it:

sudo dnf install compat-openssl10
sudo dnf install https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-7.0.3-1.rhel.7.x86_64.rpm

卸载 - Fedora 28、Fedora 29 和 Fedora 30Uninstallation - Fedora 28, 29, and 30

sudo dnf remove powershell

Arch LinuxArch Linux

备注

Arch 支持不受 Microsoft 的官方支持且由社区维护。Arch support is not officially supported by Microsoft and is maintained by the community.

Arch Linux 用户存储库 (AUR) 中提供有 PowerShell。PowerShell is available from the Arch Linux User Repository (AUR).

AUR 中的包由社区维护,并无正式支持。Packages in the AUR are community maintained; there's no official support.

若要详细了解如何从 AUR 安装包,请参阅 Arch Linux wiki在 Docker 中使用 PowerShellFor more information on installing packages from the AUR, see the Arch Linux wiki or Using PowerShell in Docker.

Snap 包Snap Package

获取 snapdGetting snapd

需具备 snapd 才能运行 Snap。snapd is required to run snaps. 按照这些说明确保你已安装 snapdUse these instructions to make sure you have snapd installed.

通过 Snap 进行安装Installation via Snap

为简化安装和更新,已向 Snap 存储发布适用于 Linux 的 PowerShell。PowerShell for Linux is published to the Snap store for easy installation and updates.

首选方法如下所示:The preferred method is as follows:

# Install PowerShell
sudo snap install powershell --classic

# Start PowerShell
pwsh

若要安装预览版本,请使用以下方法:To install a preview version, use the following method:

# Install PowerShell
sudo snap install powershell-preview --classic

# Start PowerShell
pwsh-preview

安装完成后,Snap 将自动升级。After installation, Snap will automatically upgrade. 可以使用 sudo snap refresh powershellsudo snap refresh powershell-preview 触发升级。You can trigger an upgrade using sudo snap refresh powershell or sudo snap refresh powershell-preview.

卸载Uninstallation

sudo snap remove powershell

or

sudo snap remove powershell-preview

KaliKali

备注

Kali 支持不受 Microsoft 的官方支持且由社区维护。Kali support is not officially supported by Microsoft and is maintained by the community.

安装 - KaliInstallation - Kali

# Install PowerShell package
apt update && apt -y install powershell

# Start PowerShell
pwsh

卸载 - KaliUninstallation - Kali

# Uninstall PowerShell package
apt -y remove powershell

RaspbianRaspbian

备注

Raspbian 支持是实验性的。Raspbian support is experimental.

当前仅 Raspbian Stretch 支持 PowerShell。Currently, PowerShell is only supported on Raspbian Stretch.

CoreCLR 和 PowerShell 仅适用于 Pi 2 和 Pi 3 设备,因为其他设备(如 Pi 0)有不受支持的处理器。CoreCLR and PowerShell will only work on Pi 2 and Pi 3 devices as other devices, like Pi Zero, have an unsupported processor.

下载 Raspbian Stretch 并按照安装说明操作,将其安装在你的 Pi 上。Download Raspbian Stretch and follow the installation instructions to get it onto your Pi.

安装 - RaspbianInstallation - Raspbian

###################################
# Prerequisites

# Update package lists
sudo apt-get update

# Install libunwind8 and libssl1.0
# Regex is used to ensure that we do not install libssl1.0-dev, as it is a variant that is not required
sudo apt-get install '^libssl1.0.[0-9]$' libunwind8 -y

###################################
# Download and extract PowerShell

# Grab the latest tar.gz
wget https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-7.0.3-linux-arm32.tar.gz

# Make folder to put powershell
mkdir ~/powershell

# Unpack the tar.gz file
tar -xvf ./powershell-7.0.3-linux-arm32.tar.gz -C ~/powershell

# Start PowerShell
~/powershell/pwsh

或者,可以创建可启动 PowerShell 的符号链接,而无需指定到 pwsh 二进制文件的路径。Optionally, you can create a symbolic link to start PowerShell without specifying the path to the pwsh binary.

# Start PowerShell from bash with sudo to create a symbolic link
sudo ~/powershell/pwsh -c New-Item -ItemType SymbolicLink -Path "/usr/bin/pwsh" -Target "$PSHOME/pwsh" -Force

# alternatively you can run following to create a symbolic link
# sudo ln -s ~/powershell/pwsh /usr/bin/pwsh

# Now to start PowerShell you can just run "pwsh"

卸载 - RaspbianUninstallation - Raspbian

rm -rf ~/powershell

安装预览版本Installing Preview Releases

通过包存储库安装适用于 Linux 的 PowerShell 预览版本时,包名称从 powershell 更改为 powershell-previewWhen installing a PowerShell Preview release for Linux via a Package Repository, the package name changes from powershell to powershell-preview.

直接下载安装不会更改包名称(文件名除外)。Installing via direct download doesn't change, other than the file name.

下表包含使用各种包管理器安装稳定包和预览包的命令:The following table contains the commands to install the stable and preview packages using the various package managers:

分配Distribution(s) 稳定包命令Stable Command 预览包命令Preview Command
Ubuntu、DebianUbuntu, Debian sudo apt-get install -y powershell sudo apt-get install -y powershell-preview
CentOS、RedHatCentOS, RedHat sudo yum install -y powershell sudo yum install -y powershell-preview
FedoraFedora sudo dnf install -y powershell sudo dnf install -y powershell-preview

作为 .NET 全局工具安装Install as a .NET Global tool

如果你已安装 .NET Core SDK,则可以轻松地安装 PowerShell 作为 .NET 全局工具If you already have the .NET Core SDK installed, it's easy to install PowerShell as a .NET Global tool.

dotnet tool install --global PowerShell

dotnet 工具安装程序将 ~/.dotnet/tools 添加到 PATH 环境变量中。The dotnet tool installer adds ~/.dotnet/tools to your PATH environment variable. 但是,当前运行的 shell 没有更新的 PATHHowever, the currently running shell does not have the updated PATH. 应该可以通过键入 pwsh 从新 shell 启动 PowerShell。You should be able to start PowerShell from a new shell by typing pwsh.

二进制存档Binary Archives

已对 Linux 平台提供 PowerShell 二进制 tar.gz 存档,以启用高级部署方案。PowerShell binary tar.gz archives are provided for Linux platforms to enable advanced deployment scenarios.

依赖项Dependencies

PowerShell 为所有 Linux 分发版生成可移植二进制文件。PowerShell builds portable binaries for all Linux distributions. 但是对于不同的分发版,.NET Core 运行时需要不同的依赖项,并且 PowerShell 也有相同要求。But, .NET Core runtime requires different dependencies on different distributions, and PowerShell does too.

下表列出了在不同 Linux 分发版上正式支持的 .NET Core 2.0 依赖项。The following chart shows the .NET Core 2.0 dependencies that are officially supported on different Linux distributions.

OSOS 依赖项Dependencies
Ubuntu 16.04Ubuntu 16.04 libc6、libgcc1、libgssapi-krb5-2、liblttng-ust0、libstdc++6、libc6, libgcc1, libgssapi-krb5-2, liblttng-ust0, libstdc++6,
libcurl3、libunwind8、libuuid1、zlib1g、libssl1.0.0、libicu55libcurl3, libunwind8, libuuid1, zlib1g, libssl1.0.0, libicu55
Ubuntu 17.10Ubuntu 17.10 libc6、libgcc1、libgssapi-krb5-2、liblttng-ust0、libstdc++6、libc6, libgcc1, libgssapi-krb5-2, liblttng-ust0, libstdc++6,
libcurl3、libunwind8、libuuid1、zlib1g、libssl1.0.0、libicu57libcurl3, libunwind8, libuuid1, zlib1g, libssl1.0.0, libicu57
Ubuntu 18.04Ubuntu 18.04 libc6、libgcc1、libgssapi-krb5-2、liblttng-ust0、libstdc++6、libc6, libgcc1, libgssapi-krb5-2, liblttng-ust0, libstdc++6,
libcurl3、libunwind8、libuuid1、zlib1g、libssl1.0.0、libicu60libcurl3, libunwind8, libuuid1, zlib1g, libssl1.0.0, libicu60
Debian 8 (Jessie)Debian 8 (Jessie) libc6、libgcc1、libgssapi-krb5-2、liblttng-ust0、libstdc++6、libc6, libgcc1, libgssapi-krb5-2, liblttng-ust0, libstdc++6,
libcurl3、libunwind8、libuuid1、zlib1g、libssl1.0.0、libicu52libcurl3, libunwind8, libuuid1, zlib1g, libssl1.0.0, libicu52
Debian 9 (Stretch)Debian 9 (Stretch) libc6、libgcc1、libgssapi-krb5-2、liblttng-ust0、libstdc++6、libc6, libgcc1, libgssapi-krb5-2, liblttng-ust0, libstdc++6,
libcurl3、libunwind8、libuuid1、zlib1g、libssl1.0.2、libicu57libcurl3, libunwind8, libuuid1, zlib1g, libssl1.0.2, libicu57
CentOS 7CentOS 7
Oracle Linux 7Oracle Linux 7
RHEL 7RHEL 7
libunwind、libcurl、openssl-libs、libiculibunwind, libcurl, openssl-libs, libicu
openSUSE 42.3openSUSE 42.3 libcurl4、libopenssl1_0_0、libicu52_1libcurl4, libopenssl1_0_0, libicu52_1
openSUSE Leap 15openSUSE Leap 15 libcurl4、libopenssl1_0_0、libicu60_2libcurl4, libopenssl1_0_0, libicu60_2
Fedora 27Fedora 27
Fedora 28Fedora 28
libunwind、libcurl、openssl-libs、libicu、compat-openssl10libunwind, libcurl, openssl-libs, libicu, compat-openssl10

若要在不受正式支持的 Linux 分发版上部署 PowerShell 二进制文件,则需在各个步骤中安装目标 OS 的必要依赖项。To deploy PowerShell binaries on Linux distributions that aren't officially supported, you need to install the necessary dependencies for the target OS in separate steps. 例如,Amazon Linux dockerfile 先安装依赖项,然后提取 Linux tar.gz 存档。For example, our Amazon Linux dockerfile installs dependencies first, and then extracts the Linux tar.gz archive.

安装 - 二进制存档Installation - Binary Archives

LinuxLinux

# Download the powershell '.tar.gz' archive
curl -L -o /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-7.0.3-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

卸载二进制存档Uninstalling binary archives

sudo rm -rf /usr/bin/pwsh /opt/microsoft/powershell

路径Paths

  • $PSHOME/opt/microsoft/powershell/7/$PSHOME is /opt/microsoft/powershell/7/
  • 将从 ~/.config/powershell/profile.ps1 中读取用户配置文件User profiles will be read from ~/.config/powershell/profile.ps1
  • 将从 $PSHOME/profile.ps1 中读取默认配置文件Default profiles will be read from $PSHOME/profile.ps1
  • 将从 ~/.local/share/powershell/Modules 中读取用户模块User modules will be read from ~/.local/share/powershell/Modules
  • 将从 /usr/local/share/powershell/Modules 中读取共享模块Shared modules will be read from /usr/local/share/powershell/Modules
  • 将从 $PSHOME/Modules 中读取默认模块Default modules will be read from $PSHOME/Modules
  • PSReadline 历史记录将记录到 ~/.local/share/powershell/PSReadLine/ConsoleHost_history.txtPSReadLine history will be recorded to ~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt

配置文件采用 PowerShell 的按主机配置,所以默认主机特定配置文件位于相同位置下的 Microsoft.PowerShell_profile.ps1 中。The profiles respect PowerShell's per-host configuration, so the default host-specific profiles exists at Microsoft.PowerShell_profile.ps1 in the same locations.

PowerShell 采用 Linux 上的 XDG 基目录规范PowerShell respects the XDG Base Directory Specification on Linux.

安装支持Installation support

Microsoft 支持本文档中的安装方法。Microsoft supports the installation methods in this document. 其他源可能会提供其他安装方法。There may be other methods of installation available from other sources. 尽管这些工具和方法可能有效,但 Microsoft 无法支持这些方法。While those tools and methods may work, Microsoft cannot support those methods.