在 macOS 上安裝 PowerShell 7

PowerShell 7 有多個套件版本可安裝。 本文重點介紹安裝最新的穩定版套件。 欲了解更多套件版本資訊,請參閱 PowerShell 支援生命週期 文章。

PowerShell 7 的新版本取代了先前的 PowerShell 7 版本。 PowerShell 的預覽版本可以與其他 PowerShell 版本並存安裝。 較新的預覽版本取代了先前的預覽版本。 如果你需要同時執行 PowerShell 7 和舊版本,請用二進位壓縮方法重新安裝舊版本。

選擇安裝方法

有數種方式可以在macOS上安裝PowerShell。 請選擇其中一項:

下載並安裝套件檔案

自 2026 年 5 月的 PowerShell 版本起,macOS 的 PKG 套件由 Microsoft 公證並簽署。 要安裝套件,請下載 PKG 檔案並打開它。

  1. 從發行頁面下載安裝套件。 選擇你想安裝的套件版本。

    Note

    從 macOS 27(Golden Gate)開始,macOS 僅能在 Apple Silicon(Arm64)處理器上運行。

  2. 開啟 Finder

  3. 找出下載的套件

  4. 對檔案按兩下

安裝為 .NET 全域工具

如果你已經安裝了 .NET Core SDK,可以使用 .NET Global 工具來安裝 PowerShell 7。

dotnet tool install --global PowerShell

dotnet 工具安裝程式會新增 ~/.dotnet/tools 至您的 PATH 環境變數。 不過,目前執行中的 shell 沒有更新 PATH。 從新的命令提示字元中輸入 pwsh 以啟動 PowerShell。

從二進位壓縮檔安裝 PowerShell 7

PowerShell 二進位檔案 tar.gz 提供予 macOS 平台,以啟用進階部署方案。 當您使用此方法安裝時,也必須手動安裝任何相依性。

從發行頁面下載安裝套件。 選擇你想安裝的壓縮檔版本。

使用下列命令從二進位封存安裝 PowerShell。 變更下載 URL 以符合您想要安裝的版本。

# Download the powershell '.tar.gz' archive
curl -L -o /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.6.6/powershell-7.6.6-osx-arm64.tar.gz

# Create the target folder where powershell is placed
sudo mkdir -p /usr/local/microsoft/powershell/7

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

# Set execute permissions
sudo chmod +x /usr/local/microsoft/powershell/7/pwsh

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

啟動PowerShell 7

安裝套件之後,請從終端機執行 pwsh 。 如果你安裝了預覽套件,請執行 pwsh-preview

  • 該 的位置 $PSHOME 會依你安裝的套件而異。
    • 針對穩定版與LTS套件: /usr/local/microsoft/powershell/7/
    • 預覽套件:/usr/local/microsoft/powershell/7-preview/
    • macOS 安裝套件會建立一個符號連結,/usr/local/bin/pwsh 指向位於 pwsh$PSHOME
  • 使用者設定檔會從 ~/.config/powershell/profile.ps1 讀取
  • 預設配置檔從 $PSHOME/profile.ps1 讀入
  • 用戶模組讀取自 ~/.local/share/powershell/Modules
  • 共用模組從 /usr/local/share/powershell/Modules 讀取
  • 默認模組是讀取自 $PSHOME/Modules
  • PSReadLine 歷史將記錄到 ~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt

PowerShell 遵循 macOS 上的 XDG 基底目錄規格

更新PowerShell 7

要更新 PowerShell,請下載新版本的套件或二進位壓縮檔並安裝。

卸載PowerShell 7

要解除安裝 PowerShell,你需要刪除應用程式資料夾和其他支援檔案。 以下指令會移除符號連結和 PowerShell 檔案。

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

sudo rm 來移除其他剩餘的 PowerShell 檔案和資料夾。

支援的 macOS 版本

Microsoft支援 PowerShell,直到 PowerShell 到達終止支援 或 macOS 版本達到終止支持為止。

支援的 macOS 版本如下:

  • macOS 26 (Tahoe) x64 和 Arm64
  • macOS 15 (Sequoia) x64 和 Arm64
  • macOS 14 (Sonoma) x64 和 Arm64

Apple 決定 macOS 的支援生命週期。 如需詳細資訊,請參閱下列:

支援的安裝方法

Microsoft支援本檔中的安裝方法。 可能有其他第三方安裝方法可從其他來源取得。 雖然這些工具和方法可能正常運作,但Microsoft無法支持這些方法。 欲了解更多資訊,請參閱 「安裝 PowerShell 的替代方式」。