行业资讯
📅 2026/9/2 13:05:05
PowerShell 安装指南:Windows、Linux 与 macOS 三步就位
PowerShell 安装指南Windows、Linux 与 macOS 三步就位【免费下载链接】PowerShellPowerShell for every system!项目地址: https://gitcode.com/GitHub_Trending/po/PowerShell刚接触 PowerShell 的人最常卡在三处包下错了x64 的包拿到 ARM 机器上、装完敲pwsh没反应、不知道该不该手动配 PATH。这篇文章从确认本机架构开始把一键脚本、手动装包、验证和常用配置整条路走一遍不再介绍项目背景。环境自检先确认该下哪个包安装包按「版本-系统-架构」命名架构选错是最常见的坑。Linux 和 macOS 先跑一条命令看 CPU 架构uname -m执行后你会看到x86_64、aarch64这类输出它直接决定下载包里该选哪个架构段。Windows 上在现有 PowerShell 里查处理器[System.Environment]::Is64BitOperatingSystem执行后你会看到True或FalseFalse说明是 32 位系统只能选 x86 的包。一键安装脚本有 Windows PowerShell 就先用它在 Windows PowerShell 5.1 里跑这一行脚本会自动检测系统、下载对应包并解包Invoke-Expression { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) }执行完你会看到PowerShell has been installed at 安装目录的绿色提示目录默认是%LOCALAPPDATA%\Microsoft\powershell。脚本本身放在 tools/install-powershell.ps1常用开关-Preview装 preview 构建目录自动变成~/.powershell-preview和正式版并存-Destination C:\MyPowerShell指定安装目录不填就用默认路径-AddToPathWindows 下写入用户 PATHLinux/macOS 下创建软链接-DoNotOverwrite目录已存在时直接报错而不是覆盖旧版本没有 PowerShell 的 Linux/macOS 机器用 bash 版安装器它会识别发行版并自动分流bash (curl -sL https://aka.ms/install-powershell.sh)执行完它会自己跑一遍pwsh看到 Congratulations! PowerShell is installed 即代表成功。手动部署按系统选包手动装包适合要固定版本、或不想跑脚本的场景。三个平台的包命名规则一致Windows 是PowerShell-version-win-arch.msi/.zipLinux 是powershell-version-linux-x64.tar.gzmacOS 是powershell-version-osx-x64.tar.gz。手动部署 Windows 版MSI 双击即装用命令行静默安装时msiexec /i PowerShell-version-win-x64.msi /quiet执行后无输出用pwsh -v验证即可。手动部署 Linux 版解压到固定目录再建软链接让全局可用tar zxf powershell-version-linux-x64.tar.gz -C /opt/microsoft/powershell/7 sudo ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh执行完软链接建好后任何目录下敲pwsh都能进入。手动部署 macOS 版有 Homebrew 的话走 cask 最省事brew install --cask powershell执行后终端里直接出现PS提示符。没有 Homebrew 时手动解包并链接tar zxf powershell-version-osx-x64.tar.gz -C /usr/local/powershell sudo ln -s /usr/local/powershell/pwsh /usr/local/bin/pwshPowerShell 在 macOS 上首次打开安装包时出现的授权提示装完第一件事验证版本pwsh $PSVersionTable执行后你会看到类似PSVersion 7.6.4、PSEdition Core的完整版本表仓库当前记录的稳定版是 v7.6.4见 tools/metadata.json。进阶调优三个最常用的配置点装模块进当前用户作用域不污染系统级Install-Module -Name PSReadLine -Scope CurrentUser执行后再次启动pwshGet-Module -ListAvailable PSReadLine能列出该模块即成功。查实验特性并临时开启当前仓库列出的特性见 experimental-feature-linux.jsonGet-ExperimentalFeature Enable-ExperimentalFeature -Name PSFeedbackProvider执行后你会看到带Enabled True的特性行该开关只作用于当前会话。编辑启动配置文件首次没有文件时先New-Item $PROFILE -Forcecode $PROFILE踩坑与排查症状Linux 上pwsh: command not found。排查ls -l /usr/bin/pwsh。解决多半是软链接没建成回到「手动部署 Linux 版」重跑ln -s那一步或确认你有 sudo 权限。症状Windows 报处理器架构不兼容。排查(Get-ComputerInfo -Property OsArchitecture).OsArchitecture。解决输出 32 位就换win-x86包ARM 芯片换win-arm64包重装前把旧目录清掉。症状macOS 首次打开报无法验证开发者。排查系统设置 → 隐私与安全性看是否提示被拦截。解决点仍要打开反复被拦时改用上面的 tar.gz 手动安装路径绕开 Gatekeeper 校验。延伸入口项目文档与构建说明docs/命令行与 IDE 命令示例含截图docs/cmdlet-example/各平台安装脚本源码tools/install-powershell.ps1、tools/install-powershell.shPester 测试集test/powershell/pwsh【免费下载链接】PowerShellPowerShell for every system!项目地址: https://gitcode.com/GitHub_Trending/po/PowerShell创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考