在 Alpine Linux 上安装 PowerShell
GitHub 版本页面上提供有所有可用包。 安装包以后,从终端运行 pwsh
。 若已安装预览版,请运行 pwsh-preview
。 安装之前,请查看以下支持的版本列表。
注意
PowerShell 7.4 是会删除旧版 PowerShell 7 的就地升级。 PowerShell 的预览版可以与其他版本的 PowerShell 并行安装。 如果需要与以前的版本并行运行 PowerShell 7.4,请使用二进制存档方法重新安装以前的版本。
安装步骤
Alpine 上的安装基于从版本页下载的 tar.gz 包。 包的 URL 取决于要安装的 PowerShell 版本。
- PowerShell 7.4.2 -
https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/powershell-7.4.2-linux-musl-x64.tar.gz
- PowerShell 7.3.12 -
https://github.com/PowerShell/PowerShell/releases/download/v7.3.12/powershell-7.3.12-linux-alpine-x64.tar.gz
- PowerShell 7.2.19 -
https://github.com/PowerShell/PowerShell/releases/download/v7.2.19/powershell-7.2.19-linux-alpine-x64.tar.gz
然后在终端中执行以下 shell 命令,以安装 PowerShell 7.3:
# 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.4.2/powershell-7.4.2-linux-musl-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
卸载 PowerShell
sudo rm -rf /usr/bin/pwsh /opt/microsoft/powershell
PowerShell 路径
$PSHOME
是/opt/microsoft/powershell/7/
- 配置文件脚本存储在以下位置:
- AllUsersAllHosts -
$PSHOME/profile.ps1
- AllUsersCurrentHost -
$PSHOME/Microsoft.PowerShell_profile.ps1
- CurrentUserAllHosts -
~/.config/powershell/profile.ps1
- CurrentUserCurrentHost -
~/.config/powershell/Microsoft.PowerShell_profile.ps1
- AllUsersAllHosts -
- 模块存储在以下位置:
- 用户模块 -
~/.local/share/powershell/Modules
- 共享模块 -
/usr/local/share/powershell/Modules
- 默认模块 -
$PSHOME/Modules
- 用户模块 -
- PSReadline 历史记录会记录到
~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt
中
配置文件采用 PowerShell 的按主机配置,所以默认主机特定配置文件位于相同位置下的 Microsoft.PowerShell_profile.ps1
中。
PowerShell 采用 Linux 上的 XDG 基目录规范。
支持的版本
下表列出了支持的 PowerShell 版本以及支持它们的 Alpine 版本。 这些版本在 PowerShell 到达支持终止日期或 Alpine 版本到达有效期之前仍受支持。
- 图标指示仍支持 OS 或 PowerShell 版本
- 图标指示该 OS 版本不再支持 PowerShell 版本
- 图标指示我们尚未在该 OS 上完成 PowerShell 的测试
- 图标指示不支持 OS 或 PowerShell 版本
- 当 OS 版本和 PowerShell 版本都具有 图标时,将支持该组合
Alpine | 7.2(LTS-早期) | 7.3 | 7.4(LTS-当前) |
---|---|---|---|
3.18 | |||
3.17 | |||
3.16 | |||
3.15 | |||
3.14 |
以下处理器体系结构在 Alpine 上支持 PowerShell。
Alpine | 7.2 (LTS-current) | 7.3 | 7.4(LTS-当前) |
---|---|---|---|
所有支持的版本 | X64 | X64 | X64 |
PowerShell 未在使用 Arm 处理器的 Alpine 上进行测试。
安装支持
Microsoft 支持本文档中的安装方法。 其他第三方源可能会提供其他安装方法。 尽管这些工具和方法可能有效,但 Microsoft 无法支持这些方法。
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈