HoRain云--2026最新PowerShell跨平台安装指南
🎬 HoRain 云小助手:个人主页
⛺️生活的理想,就是为了理想的生活!
⛳️ 推荐
前些天发现了一个超棒的服务器购买网站,性价比超高,大内存超划算!忍不住分享一下给大家。点击跳转到网站。
目录
⛳️ 推荐
PowerShell 安装指南 (2026)
📌 快速查看当前版本
一、Windows 系统安装
方法1:通过 Microsoft Store(最简单)⭐
方法2:使用 MSI 安装包(推荐)
方法3:使用 winget(Windows 11推荐)
方法4:使用 Chocolatey(软件包管理器)
⚠️ 重要提示:启用执行策略
二、Linux 系统安装
Ubuntu/Debian
CentOS/RHEL/Fedora
openSUSE/SLES
Arch Linux
三、macOS 系统安装
方法1:使用 Homebrew(推荐)⭐
方法2:下载PKG安装包
方法3:使用 MacPorts
四、验证安装
五、常见问题解决
❗ 问题1: pwsh 命令找不到
❗ 问题2: 执行策略限制
❗ 问题3: .NET Framework 依赖缺失
六、卸载 PowerShell
Windows
macOS
Linux
七、升级 PowerShell
Windows (winget)
macOS (Homebrew)
Linux
八、推荐的后续操作
📋 安装方式对比表
PowerShell 安装指南 (2026)
PowerShell 是微软开发的任务自动化与配置管理框架,现已实现跨平台支持(Windows/Linux/macOS)。以下是完整安装教程:
📌 快速查看当前版本
# 检查是否已安装 pwsh --version # PowerShell 7+ powershell.exe -version # Windows PowerShell 5.1+一、Windows 系统安装
方法1:通过 Microsoft Store(最简单)⭐
- 打开Microsoft Store
- 搜索 "PowerShell"
- 点击获取/安装
- 完成后运行
pwsh启动
方法2:使用 MSI 安装包(推荐)
| 系统架构 | 下载地址 |
|---|---|
| Windows x64 | https://github.com/PowerShell/PowerShell/releases/latest/download/PowerShell-7.x-win-x64.msi |
| Windows ARM64 | https://github.com/PowerShell/PowerShell/releases/latest/download/PowerShell-7.x-win-arm64.msi |
| Windows x86 | https://github.com/PowerShell/PowerShell/releases/latest/download/PowerShell-7.x-win-x86.msi |
安装步骤:
# 1. 下载 MSI 安装包 Invoke-WebRequest -Uri "https://github.com/PowerShell/PowerShell/releases/latest/download/PowerShell-7.x-win-x64.msi" -OutFile "PSInstaller.msi" # 2. 静默安装 msiexec /i PSInstaller.msi /quiet # 3. 验证安装 pwsh --version方法3:使用 winget(Windows 11推荐)
# 安装最新版本 winget install Microsoft.PowerShell # 查看安装状态 winget list PowerShell # 升级已安装的 PowerShell winget upgrade PowerShell方法4:使用 Chocolatey(软件包管理器)
# 先安装 Chocolatey Set-ExecutionPolicy Bypass -Scope Process -Force [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) # 然后安装 PowerShell choco install powershell-core -y⚠️ 重要提示:启用执行策略
如果运行脚本时遇到权限错误,需要先修改执行策略:
# 以管理员身份运行 PowerShell # 查看当前执行策略 Get-ExecutionPolicy # 改为 RemoteSigned(推荐) Set-ExecutionPolicy RemoteSigned -Scope CurrentUser # 确认更改 Get-ExecutionPolicy二、Linux 系统安装
Ubuntu/Debian
# 安装依赖 wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb rm packages-microsoft-prod.deb # 更新并安装 PowerShell sudo apt-get update sudo apt-get install -y powershellCentOS/RHEL/Fedora
# RHEL/CentOS 8+ curl -sSL https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm | sudo rpm -ivh sudo dnf install -y powersecl # Fedora curl -sSL https://packages.microsoft.com/config/fedora/39/packages-microsoft-prod.rpm | sudo rpm -ivh sudo dnf install -y powershellopenSUSE/SLES
# openSUSE Leap 15.x sudo zypper ar https://packages.microsoft.com/yumrepos/powershell7-rpm.repo microsoft-repo sudo zypper refresh sudo zypper in powershell # SUSE Linux Enterprise Server sudo Zypper addrepo https://packages.microsoft.com/yumrepos/powershell7-rpm.repo MicrosoftRepo sudo zypper ref && sudo zypper in powershellArch Linux
# 从 AUR 安装(使用 yay 或 paru) yay -S powershell-bin # 或使用 pacman # 注意:可能需要先添加 AUR 源三、macOS 系统安装
方法1:使用 Homebrew(推荐)⭐
# 安装 Homebrew(如未安装) /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # 安装 PowerShell brew install --cask powershell # 验证安装 pwsh --version方法2:下载PKG安装包
- 访问 https://github.com/PowerShell/PowerShell/releases/latest
- 下载
powershell-X.X.X-osx-x64.pkg - 双击运行并完成安装
方法3:使用 MacPorts
# 安装 MacPorts # 然后安装 PowerShell sudo port install powershell7四、验证安装
# 所有系统通用 pwsh --version # 查看详细信息 $PSVersionTable.PSVersion $PSVersionTable.PSEdition $PSVersionTable.OS预期输出示例:
7.4.5 # PowerShell 版本 Core # Edition Darwin # OS (macOS) / Linux / WinNT (Windows)五、常见问题解决
❗ 问题1:pwsh命令找不到
# Windows: 添加到环境变量 PATH # Linux/macOS: 创建符号链接 ln -s /usr/local/bin/pwsh /usr/bin/pwsh❗ 问题2: 执行策略限制
# 临时允许执行当前目录的脚本 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser # 永久生效(需管理员) Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine❗ 问题3: .NET Framework 依赖缺失
# Linux 上可能需要的依赖 sudo apt-get install -y dotnet-hostfxr-8.0六、卸载 PowerShell
Windows
# 通过设置→应用和功能 # 或使用命令行 Remove-Item "C:\Program Files\PowerShell\*" -Recurse -ForcemacOS
# 移除 Homebrew 安装 brew uninstall --cask powershell # 手动删除 sudo rm -rf /usr/local/bin/pwsh sudo rm -rf /Applications/Microsoft\ PowerShellLinux
# Debian/Ubuntu sudo apt-get remove powershell # CentOS/RHEL sudo dnf remove powershell # 清理配置文件 sudo rm -rf /etc/powershell七、升级 PowerShell
Windows (winget)
winget upgrade PowerShellmacOS (Homebrew)
brew upgrade --cask powershellLinux
# Ubuntu/Debian sudo apt-get update && sudo apt-get upgrade powershell # CentOS/RHEL sudo dnf upgrade powershell八、推荐的后续操作
# 1. 测试基本功能 Write-Host "欢迎使用 PowerShell!" -ForegroundColor Green Get-Service | Select-Object Name, Status # 2. 安装 VS Code + PowerShell 扩展(代码编辑) # 3. 探索模块 Install-Module PSReadLine # 4. 学习资源 Get-Help about_ Get-Command | Measure-Object | Select-Object Count📋 安装方式对比表
| 方法 | Windows | Linux | macOS | 难度 | 推荐度 |
|---|---|---|---|---|---|
| Microsoft Store | ✅ | ❌ | ❌ | ⭐ | ⭐⭐⭐⭐⭐ |
| MSI 安装包 | ✅ | ❌ | ❌ | ⭐⭐ | ⭐⭐⭐⭐⭐ |
| Homebrew | ❌ | ❌ | ✅ | ⭐⭐ | ⭐⭐⭐⭐⭐ |
| winget | ✅ | ❌ | ❌ | ⭐⭐ | ⭐⭐⭐⭐ |
| Chocolatey | ✅ | ❌ | ❌ | ⭐⭐⭐ | ⭐⭐⭐⭐ |
| 官方仓库 | ✅ | ✅ | ✅ | ⭐⭐⭐ | ⭐⭐⭐⭐ |
| 下载PKG | ✅ | ❌ | ✅ | ⭐⭐ | ⭐⭐⭐⭐ |
✅ 完成以上任一方法后,你就可以开始使用 PowerShell 进行系统管理和自动化任务了!如需了解具体用法,可以继续提问!
❤️❤️❤️本人水平有限,如有纰漏,欢迎各位大佬评论批评指正!😄😄😄
💘💘💘如果觉得这篇文对你有帮助的话,也请给个点赞、收藏下吧,非常感谢!👍 👍 👍
🔥🔥🔥Stay Hungry Stay Foolish 道阻且长,行则将至,让我们一起加油吧!🌙🌙🌙
