当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 Alpine Linux 上安装 PowerShell

作者:精品下载站 日期:2024-12-14 03:06:54 浏览:16 分类:玩电脑

在 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.4 - https://github.com/PowerShell/PowerShell/releases/download/v7.4.4/powershell-7.4.4-linux-musl-x64.tar.gz
  • PowerShell 7.2.22 - https://github.com/PowerShell/PowerShell/releases/download/v7.2.22/powershell-7.2.22-linux-alpine-x64.tar.gz
  • PowerShell 7.5-preview.3 - https://github.com/PowerShell/PowerShell/releases/download/v7.5.0-preview.3/powershell-7.5.0-preview.3-linux-musl-x64。 .tar.gz

然后,在终端中执行以下 shell 命令来安装 PowerShell 7.4:

# 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.4/powershell-7.4.4-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
  • 模块存储在以下位置:

    • 用户模块 - ~/.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 基本目录规范。

    支持的版本

    Microsoft 支持 PowerShell,直到 PowerShell 终止支持或 Alpine 版本终止。

    包含适用于 x64 的 PowerShell 7.2、PowerShell 7.4 和 PowerShell 7.5 预览版的 Docker 映像可从 Microsoft Artifact Registry 获取以下版本的 Alpine:

    • Alpine 3.17 - 操作系统支持将于 2024 年 11 月 22 日结束

    PowerShell 的 Docker 映像不适用于 Alpine 3.18 和 3.19。

    这很重要

    Docker 映像是根据操作系统发行商提供的官方操作系统 (OS) 映像构建的。这些映像可能没有最新的安全更新。 Microsoft 建议您将操作系统软件包更新到最新版本,以确保应用最新的安全更新。

    安装支持

    Microsoft 支持本文档中的安装方法。其他第三方来源可能还提供其他安装方法。虽然这些工具和方法可能有效,但 Microsoft 无法支持这些方法。

    您需要 登录账户 后才能发表评论

    取消回复欢迎 发表评论:

    关灯